Skip to content

Commit

Permalink
Merge pull request #517 from oceanprotocol/issue510-match-providers-a…
Browse files Browse the repository at this point in the history
…lgo-dataset

Match dataset providers with private algorithms providers
  • Loading branch information
bogdanfazakas authored Jul 2, 2021
2 parents 1c4ba14 + 1ceb0f6 commit c6c5021
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/components/organisms/AssetActions/Compute/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ export default function Compute({
source.token
)
setDdoAlgorithmList(gueryResults.results)
const datasetComputeService = ddo.findServiceByType('compute')
algorithmSelectionList = await transformDDOToAssetSelection(
datasetComputeService?.serviceEndpoint,
gueryResults.results,
config.metadataCacheUri,
[]
Expand Down Expand Up @@ -385,7 +387,10 @@ export default function Compute({
text="This algorithm has been set to private by the publisher and can't be downloaded. You can run it against any allowed data sets though!"
state="info"
/>
<AlgorithmDatasetsListForCompute algorithmDid={ddo.id} />
<AlgorithmDatasetsListForCompute
algorithmDid={ddo.id}
dataset={ddo}
/>
</>
) : (
<Formik
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/AssetActions/Consume.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default function Consume({
</div>
</div>
{type === 'algorithm' && (
<AlgorithmDatasetsListForCompute algorithmDid={ddo.id} />
<AlgorithmDatasetsListForCompute algorithmDid={ddo.id} dataset={ddo} />
)}
<footer className={styles.feedback}>
<Web3Feedback isBalanceSufficient={isBalanceSufficient} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export default function FormEditComputeDataset({
config.metadataCacheUri,
source.token
)
const datasetComputeService = ddo.findServiceByType('compute')
const algorithmSelectionList = await transformDDOToAssetSelection(
datasetComputeService?.serviceEndpoint,
querryResult.results,
config.metadataCacheUri,
publisherTrustedAlgorithms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { AssetSelectionAsset } from '../../molecules/FormFields/AssetSelection'
import AssetComputeList from '../../molecules/AssetComputeList'
import { useOcean } from '../../../providers/Ocean'
import { useAsset } from '../../../providers/Asset'
import { DDO } from '@oceanprotocol/lib'

export default function AlgorithmDatasetsListForCompute({
algorithmDid
algorithmDid,
dataset
}: {
algorithmDid: string
dataset: DDO
}): ReactElement {
const { config } = useOcean()
const { type } = useAsset()
Expand All @@ -18,8 +21,10 @@ export default function AlgorithmDatasetsListForCompute({

useEffect(() => {
async function getDatasetsAllowedForCompute() {
const datasetComputeService = dataset.findServiceByType('compute')
const datasets = await getAlgorithmDatasetsForCompute(
algorithmDid,
datasetComputeService?.serviceEndpoint,
config.metadataCacheUri
)
setDatasetsForCompute(datasets)
Expand Down
13 changes: 12 additions & 1 deletion src/utils/aquarius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export async function getAssetsNames(
}

export async function transformDDOToAssetSelection(
datasetProviderEndpoint: string,
ddoList: DDO[],
metadataCacheUri: string,
selectedAlgorithms?: PublisherTrustedAlgorithm[]
Expand All @@ -126,14 +127,22 @@ export async function transformDDOToAssetSelection(
const didList: string[] = []
const priceList: PriceList = await getAssetsPriceList(ddoList)
const symbolList: any = {}
const didProviderEndpointMap: any = {}
for (const ddo of ddoList) {
didList.push(ddo.id)
symbolList[ddo.id] = ddo.dataTokenInfo.symbol
const algoComputeService = ddo.findServiceByType('compute')
algoComputeService?.serviceEndpoint &&
(didProviderEndpointMap[ddo.id] = algoComputeService?.serviceEndpoint)
}
const ddoNames = await getAssetsNames(didList, metadataCacheUri, source.token)
const algorithmList: AssetSelectionAsset[] = []
didList?.forEach((did: string) => {
if (priceList[did]) {
if (
priceList[did] &&
(!didProviderEndpointMap[did] ||
didProviderEndpointMap[did] === datasetProviderEndpoint)
) {
let selected = false
selectedAlgorithms?.forEach((algorithm: PublisherTrustedAlgorithm) => {
if (algorithm.did === did) {
Expand Down Expand Up @@ -162,6 +171,7 @@ export async function transformDDOToAssetSelection(

export async function getAlgorithmDatasetsForCompute(
algorithmId: string,
datasetProviderUri: string,
metadataCacheUri: string
): Promise<AssetSelectionAsset[]> {
const source = axios.CancelToken.source()
Expand All @@ -183,6 +193,7 @@ export async function getAlgorithmDatasetsForCompute(
return []
}
const datasets = await transformDDOToAssetSelection(
datasetProviderUri,
computeDatasetsForCurrentAlgorithm,
metadataCacheUri,
[]
Expand Down

1 comment on commit c6c5021

@vercel
Copy link

@vercel vercel bot commented on c6c5021 Jul 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.