Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed May 21, 2024
2 parents c153c96 + 53b91a3 commit 9d225c6
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "v[0-9]+.[0-9]+.[0-9]+"

env:
DEPLOYMENT: scanr-next-gen
DEPLOYMENT: scanr-ui
DEPLOYMENT_NAMESPACE: scanr
DEPLOYMENT_URL: https://scanr.dataesr.ovh
MM_NOTIFICATION_CHANNEL: bots
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- staging

env:
DEPLOYMENT: scanr-next-gen
DEPLOYMENT: scanr-ui
DEPLOYMENT_NAMESPACE: scanr
DEPLOYMENT_URL: https://scanr.staging.dataesr.ovh
MM_NOTIFICATION_CHANNEL: bots
Expand Down
1 change: 0 additions & 1 deletion client/src/api/networks/network/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,5 @@ export default function configCreate(model: string): NetworkConfig {
...(terminology && { terminology: terminology }),
}

console.log("config", config)
return config
}
26 changes: 0 additions & 26 deletions client/src/api/networks/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ export default async function networkCreate(
}))
})

console.log(`Graph items=${graph.order}, links=${graph.size}, components=${connectedComponents(graph).length}`)

// Keep only largests components
const sortedComponents = connectedComponents(graph).sort((a, b) => b.length - a.length)
let numberOfComponents = GRAPH_MAX_COMPONENTS
Expand All @@ -65,38 +63,15 @@ export default async function networkCreate(
numberOfComponents -= 1
graph = subgraph(graph, sortedComponents.slice(0, numberOfComponents).flat())
}
console.log(`Components graph items=${graph.order}, links=${graph.size}, components=${connectedComponents(graph).length}`)

// Filter with minimal number of nodes
// let nodeWeightThresh = 1
// while (graph.order > GRAPH_MAX_ORDER) {
// nodeWeightThresh += 1
// graph = subgraph(graph, (_, attr) => attr?.weight >= nodeWeightThresh) // eslint-disable-line no-loop-func
// }

// console.log(`Filtered graph items=${graph.order}, links=${graph.size}, components=${connectedComponents(graph).length}`)

// Filter with minimal number of edges
// let edgeWeightThresh = 1
// while (graph.size / graph.order > GRAPH_MAX_RATIO) {
// edgeWeightThresh += 1
// graph.filterEdges((edge, attr) => attr?.weight < edgeWeightThresh).forEach((edge) => graph.dropEdge(edge)) // eslint-disable-line no-loop-func
// graph = subgraph(graph, (node) => graph.degree(node) > 0) // eslint-disable-line no-loop-func
// }
// console.log("Edge weight threshold :", edgeWeightThresh)

// Add forceAtlas layout
random.assign(graph) // Needs a starting layout for forceAtlas to work
const sensibleSettings = forceAtlas2.inferSettings(graph)
forceAtlas2.assign(graph, { iterations: 100, settings: sensibleSettings })
console.log("Atlas2 settings", sensibleSettings)

// Add communities
const communities = await communitiesCreate(graph, computeClusters)

console.log("Communities", communities)
console.log("Graph nodes", Array.from(graph.nodeEntries()))

// Create network
const network: NetworkData = {
items: graph.mapNodes((key, attr) => ({
Expand All @@ -117,6 +92,5 @@ export default async function networkCreate(
clusters: communities,
}

console.log("network", network)
return network
}
3 changes: 0 additions & 3 deletions client/src/api/networks/network/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ async function mistralLabelsFromDomains(domains: string): Promise<string> {
randomSeed: 42,
})

console.log("mistral_completion", completion)
const answer: string = completion.choices[0].message.content
return answer
}
Expand All @@ -52,15 +51,13 @@ export async function openAiLabeledClusters(clusters: NetworkCommunities): Promi
}
return acc
}, "") as string
console.log("domains", domains)

if (!domains) return clusters

const mistral_labels = await mistralLabelsFromDomains(domains).then(
(response) => JSON.parse(response),
(err) => console.log(err)
)
console.log("mistral_labels", mistral_labels)
if (!mistral_labels || mistral_labels.constructor != Object) {
return clusters
}
Expand Down
3 changes: 0 additions & 3 deletions client/src/api/networks/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export async function networkSearch({ model, query, options, filters }: NetworkS

if (filters && filters.length > 0) body.query.bool.filter = filters
if (!query) body.query = { function_score: { query: body.query, random_score: {} } }
console.log("networkSearch", body)

const res = await fetch(`${publicationsIndex}/_search`, {
method: "POST",
Expand All @@ -46,7 +45,6 @@ export async function networkSearch({ model, query, options, filters }: NetworkS
throw new Error(`Elasticsearch error: ${res.status}`)
}
const json = await res.json()
console.log("endOfSearch", json)

const aggregation = json.aggregations?.[model].buckets
if (!aggregation?.length) {
Expand All @@ -69,7 +67,6 @@ export async function networkSearch({ model, query, options, filters }: NetworkS
info: info,
}

console.log("data", data)
return data
}

Expand Down
47 changes: 28 additions & 19 deletions client/src/hooks/useConsent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,75 @@ import { useEffect, useState } from "react";

type Consent = {
[key: string]: 0 | 1;
}
};

type UseConsent = {
consent: Consent;
setConsent: (newConcent: Consent) => void;
set: boolean;
dialogId: string;
}
};

if (typeof Proxy === "undefined") {
throw new Error("This browser doesn't support Proxy");
}

const dialogId = 'fr-consent-dialog';
const consentKey = 'consent';
const dialogId = "fr-consent-dialog";
const consentKey = "consent";

export default function useConsent(defaultConsent: Consent = {}): UseConsent {
const [set, setSet] = useState<boolean>(false);
const readValue = (): Consent => {
const storedConsentString = localStorage.getItem(consentKey);
const storedConsent = storedConsentString ? JSON.parse(storedConsentString) : null;
let storedConsentString = localStorage.getItem(consentKey);
let storedConsent = null;
try {
storedConsent = JSON.parse(storedConsentString);
} catch (e) {
storedConsentString = "";
}
setSet(!!storedConsent);
return storedConsent || defaultConsent;
}
};
const [innerConsent, setInnerConsent] = useState<Consent>(() => readValue());

const consent = new Proxy(innerConsent, {
get: function (target, key) {
if (typeof key === 'string') {
if (typeof key === "string") {
return target[key];
}
return undefined;
},
set: function (target, key, val) {
if (typeof key === 'string') {
if (typeof key === "string") {
setInnerConsent({ ...innerConsent, [key]: val });
target[key] = val;
return true;
}
return false;
}
},
});

const setConsent = (newConcent) => {
localStorage.setItem(consentKey, JSON.stringify(newConcent || innerConsent));
window.dispatchEvent(new StorageEvent('local-storage', { key: consentKey }))
}
localStorage.setItem(
consentKey,
JSON.stringify(newConcent || innerConsent)
);
window.dispatchEvent(
new StorageEvent("local-storage", { key: consentKey })
);
};

useEffect(() => {
const handleStorage = (e: StorageEvent) => {
if (e.key === consentKey) {
setInnerConsent(readValue());
}
}
window.addEventListener('local-storage', handleStorage);
};
window.addEventListener("local-storage", handleStorage);
return () => {
window.removeEventListener('local-storage', handleStorage);
}
window.removeEventListener("local-storage", handleStorage);
};
});


return { consent, setConsent, set, dialogId };
}
}
2 changes: 1 addition & 1 deletion client/src/layout/components/footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export default function MainFooter() {
target="_blank"
rel="noreferer noopenner"
className="fr-footer__bottom-link"
href={`https://github.com/dataesr/scanr-next-gen/releases/tag/v${version}`}
href={`https://github.com/dataesr/scanr-ui/releases/tag/v${version}`}
>
{intl.formatMessage({ id: "layout.footer.version" }, { version })}
</Link>
Expand Down
1 change: 0 additions & 1 deletion client/src/pages/networks/components/analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default function ClustersAnalytics({ clustersTabs, show }: { clustersTabs
const sizeChartOptions = getSizeChartOptions({ data: clusters.slice(0, 10) })
const oaChartOptions = getOaChartOptions({ data: clusters.slice(0, 10) })
const yearsChartOptions = getYearsChartOptions({ data: clusters.slice(0, 10) })
console.log(yearsChartOptions)

return (
<Row>
Expand Down
3 changes: 2 additions & 1 deletion client/src/pages/networks/components/graph.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useMemo } from "react"
import { Container, Spinner } from "@dataesr/dsfr-plus"
import { VOSviewerOnline } from "vosviewer-online"
import { useDSFRConfig } from "@dataesr/dsfr-plus"
import useSearchData from "../hooks/useSearchData"
import Error204 from "./error204"

export default function Graph({ currentTab, computeClusters }: { currentTab: string; computeClusters: boolean }) {
const { search, currentQuery, filters } = useSearchData(currentTab, false)
const { search: searchClusters } = useSearchData(currentTab, computeClusters)
const { locale: lang } = useDSFRConfig()
const keyClusters = searchClusters.isFetching ? false : computeClusters
const vosviewer = keyClusters ? searchClusters?.data : search?.data
const lang = document.documentElement.getAttribute("lang")
const key = useMemo(
() => JSON.stringify({ currentTab, currentQuery, filters, keyClusters, lang }),
[currentTab, currentQuery, filters, keyClusters, lang]
Expand Down
1 change: 0 additions & 1 deletion client/src/pages/networks/hooks/useExportData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default function useExportData() {
setIsLoading(true)
const network = exportNetwork(search?.data?.network)
const blob = exporter(format)(network)
console.log("blob", blob)
const url = window.URL.createObjectURL(blob)
const link = document.createElement("a")
link.href = url
Expand Down
3 changes: 2 additions & 1 deletion client/src/pages/networks/hooks/useSearchData.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useQuery } from "@tanstack/react-query"
import { useMemo } from "react"
import { useDSFRConfig } from "@dataesr/dsfr-plus"
import useUrl from "../../search/hooks/useUrl"
import useTab from "./useTab"
import { networkSearch } from "../../../api/networks/search/search"

export default function useSearchData(networkTab: string, computeClusters: boolean) {
const { currentQuery, filters } = useUrl()
const { currentTab } = useTab()
const lang = document.documentElement.getAttribute("lang")
const { locale: lang } = useDSFRConfig()

const { data, error, isFetching } = useQuery({
queryKey: ["network", networkTab, currentQuery, filters, computeClusters, lang],
Expand Down

0 comments on commit 9d225c6

Please sign in to comment.