From 1e4254130370ac14300f9fad651254d6e4b57315 Mon Sep 17 00:00:00 2001 From: vmonakhov Date: Sat, 28 Sep 2024 00:42:25 +0300 Subject: [PATCH 01/10] json result --- src/components/CognateAnalysisModal/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/CognateAnalysisModal/index.js b/src/components/CognateAnalysisModal/index.js index c83b1c57..3e274d25 100644 --- a/src/components/CognateAnalysisModal/index.js +++ b/src/components/CognateAnalysisModal/index.js @@ -208,6 +208,7 @@ const computeSwadeshAnalysisMutation = gql` transcription_count result xlsx_url + json_url minimum_spanning_tree embedding_2d embedding_3d @@ -236,6 +237,7 @@ const computeMorphCognateAnalysisMutation = gql` transcription_count result xlsx_url + json_url minimum_spanning_tree embedding_2d embedding_3d @@ -1260,6 +1262,7 @@ class CognateAnalysisModal extends React.Component { result: null, xlsx_url: "", + json_url: "", figure_url: "", minimum_spanning_tree: [], @@ -2890,6 +2893,8 @@ class CognateAnalysisModal extends React.Component { {this.state.result.length > 0 && mode !== "suggestions" && mode !== "multi_suggestions" && (
{this.context("XLSX-exported analysis results")} +

+ {this.context("JSON-exported analysis results")}

)} From 63b4522b0f0361792c29fed0c4523a9a5d84f766 Mon Sep 17 00:00:00 2001 From: vmonakhov Date: Sat, 28 Sep 2024 22:05:22 +0300 Subject: [PATCH 02/10] fixe and refactoring --- src/components/CognateAnalysisModal/index.js | 35 ++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/components/CognateAnalysisModal/index.js b/src/components/CognateAnalysisModal/index.js index 3e274d25..f1156677 100644 --- a/src/components/CognateAnalysisModal/index.js +++ b/src/components/CognateAnalysisModal/index.js @@ -176,6 +176,7 @@ const computeCognateAnalysisMutation = gql` translation_count result xlsx_url + json_url figure_url minimum_spanning_tree embedding_2d @@ -2801,9 +2802,28 @@ class CognateAnalysisModal extends React.Component { const { language_list, perspectiveSelectionCountMap } = this.state; + const disabledCompute = ( + (!multi && (this.perspective_list.length <= 1 || + !this.state.perspectiveSelectionList.some(enabled => enabled))) || + (multi && + (language_list.length <= 0 || + (mode === "multi_reconstruction" && + language_list.filter(language => perspectiveSelectionCountMap[id2str(language.id)] > 0).length <= + 1) || + perspectiveSelectionCountMap[""] <= 0)) || + this.state.computing + ) + return (
- + { + if (e.key === 'Enter' && !disabledCompute) this.handleCreate(); }} + tabIndex = "0" + closeIcon + onClose={this.props.closeModal} + dimmer open + size="fullscreen" className="lingvo-modal2"> {mode === "acoustic" ? this.context("Cognate acoustic analysis") @@ -2842,18 +2862,7 @@ class CognateAnalysisModal extends React.Component { ) } onClick={this.handleCreate} - disabled={ - (!multi && - (this.perspective_list.length <= 1 || - !this.state.perspectiveSelectionList.some(enabled => enabled))) || - (multi && - (language_list.length <= 0 || - (mode === "multi_reconstruction" && - language_list.filter(language => perspectiveSelectionCountMap[id2str(language.id)] > 0).length <= - 1) || - perspectiveSelectionCountMap[""] <= 0)) || - this.state.computing - } + disabled={disabledCompute} className="lingvo-button-violet" />
From ffe558f5cb36e97747e1862049e09138f37957a3 Mon Sep 17 00:00:00 2001 From: vmonakhov Date: Wed, 2 Oct 2024 22:53:35 +0300 Subject: [PATCH 08/10] enhanced frontend --- src/pages/ComplexDistance/index.js | 147 +++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/pages/ComplexDistance/index.js diff --git a/src/pages/ComplexDistance/index.js b/src/pages/ComplexDistance/index.js new file mode 100644 index 00000000..8227f784 --- /dev/null +++ b/src/pages/ComplexDistance/index.js @@ -0,0 +1,147 @@ +import { connect } from "react-redux"; +import { Button, Dimmer, Icon, Input, Label, Loader, Message, Segment } from "semantic-ui-react"; +import { gql, useMutation } from "@apollo/client"; +import React, { useContext, useState, useEffect } from "react"; + +import TranslationContext from "Layout/TranslationContext"; + +const complexDistanceMutation = gql` + mutation complexDistance ( + $resultPool: [ObjectVal]! + $debugFlag: Boolean + ) { + complex_distance( + result_pool: $resultPool + debug_flag: $debugFlag + ) { + result + minimum_spanning_tree + embedding_2d + embedding_3d + language_name_list + message + triumph + } + } +`; + +const ComplexDistance = connect(state => state.user)(({user}) => { + + const [cleanResult, setCleanResult] = useState(false); + const [fileSuite, setFileSuite] = useState(null); + const [getComplexDistance, { data, error, loading }] = useMutation(complexDistanceMutation); + + useEffect(() => setCleanResult(false), [loading, data]); + const getTranslation = useContext(TranslationContext); + + const debugFlag = false; + + const runMutation = () => { + + if (loading) + return; + + const resultPool = []; + + for (const file of fileSuite) { + const reader = new FileReader(); + reader.onload = () => { resultPool.push(JSON.parse(reader.result)); } + reader.readAsText(file); + }; + + if (resultPool.length > 0) { + getComplexDistance( + { variables: + { + resultPool, + debugFlag + } + } + ); + } + } + + const fail = !data || !data.complex_distance.triumph; + + return ( +
+ {(user.id === undefined) && !loading ? ( + + {getTranslation("Please sign in")} +

{getTranslation("This page is available for registered users only")}

+
+ ) : loading ? ( + + + {getTranslation("Loading")}... + + + ) : ( + { if (e.key === 'Enter') runMutation(); }} tabIndex="0"> + + { getTranslation( + fileSuite ? "Json file(s) for complex result:" : "Please select result file(s) for calculating." + )} + + + { fileSuite && fileSuite.map(({ name: fileName }) => ( + + ))} + + + + setFileSuite(Array.from(e.target.files))} + /> +

+

+ ); +}) + +ComplexDistance.contextType = TranslationContext; + +export default ComplexDistance; From 798e0579947ef1942c881aa5c3f459b538a8ee25 Mon Sep 17 00:00:00 2001 From: vmonakhov Date: Thu, 3 Oct 2024 18:51:54 +0300 Subject: [PATCH 09/10] debugging --- src/pages/ComplexDistance/index.js | 32 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/pages/ComplexDistance/index.js b/src/pages/ComplexDistance/index.js index 8227f784..4483a21d 100644 --- a/src/pages/ComplexDistance/index.js +++ b/src/pages/ComplexDistance/index.js @@ -41,23 +41,24 @@ const ComplexDistance = connect(state => state.user)(({user}) => { if (loading) return; - const resultPool = []; + const resultPool = new Array(fileSuite.length); - for (const file of fileSuite) { + for (const [index, file] of fileSuite.entries()) { const reader = new FileReader(); - reader.onload = () => { resultPool.push(JSON.parse(reader.result)); } - reader.readAsText(file); - }; - - if (resultPool.length > 0) { - getComplexDistance( - { variables: - { - resultPool, - debugFlag - } + reader.onload = () => { + resultPool[index] = JSON.parse(reader.result); + if ((index + 1) == fileSuite.length) { + getComplexDistance( + { variables: + { + resultPool, + debugFlag + } + } + ); } - ); + }; + reader.readAsText(file); } } @@ -77,7 +78,7 @@ const ComplexDistance = connect(state => state.user)(({user}) => { ) : ( - { if (e.key === 'Enter') runMutation(); }} tabIndex="0"> + { if (e.key === 'Enter') document.getElementById("get-result").click(); }} tabIndex="0"> { getTranslation( fileSuite ? "Json file(s) for complex result:" : "Please select result file(s) for calculating." @@ -105,6 +106,7 @@ const ComplexDistance = connect(state => state.user)(({user}) => {