Skip to content

Commit

Permalink
Celery task
Browse files Browse the repository at this point in the history
  • Loading branch information
vmonakhov committed Feb 13, 2025
1 parent b1221e5 commit 694ff9b
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/Layout/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Organizations from "pages/Organizations";
import Perspective from "pages/Perspective";
import Requests from "pages/Requests";
import Search from "pages/Search";
import Suggestions from "pages/Suggestions";
import SupportRoute from "pages/SupportRoute";
import ToolsRoute from "pages/ToolsRoute";
import TopSectionSelector from "pages/TopSectionSelector";
Expand Down Expand Up @@ -65,6 +66,7 @@ const AppRoutes = () => (
<Route path="/import_corpora" element={<CorpImport />} />
<Route path="/import_dialeqt" element={<DialeqtImport />} />
<Route path="/dictionary/:pcid/:poid/perspective/:cid/:oid/*" element={<Perspective />} />
<Route path="/suggestions/:sugg" element={<Suggestions />} />
<Route path="/files" element={<Files />} />
<Route path="/edit_translations" element={<EditTranslations />} />
<Route path="/organizations" element={<Organizations />} />
Expand Down
130 changes: 91 additions & 39 deletions src/components/CognateAnalysisModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ const wordsQuery = gql`
}
`;

const resultSuggestionsQuery = gql`
query resultSuggestions(
$resultFile: Float!
) {
result_suggestions (
result_file: $resultFile
) {
suggestion_list
perspective_name_list
transcription_count
}
}
`;

const computeCognateAnalysisMutation = gql`
mutation computeCognateAnalysis(
$sourcePerspectiveId: LingvodocID!
Expand Down Expand Up @@ -1439,6 +1453,7 @@ class CognateAnalysisModal extends React.Component {
this.suggestions_render = this.suggestions_render.bind(this);
this.browse_files_render = this.browse_files_render.bind(this);
this.stopMutation = this.stopMutation.bind(this);
this.getResultData = this.getResultData.bind(this);

this.sg_connect = this.sg_connect.bind(this);
}
Expand Down Expand Up @@ -2440,7 +2455,7 @@ class CognateAnalysisModal extends React.Component {
// and we don't have to initialize prediction model for every single word

const groups = [];
const group_size = 4;
const group_size = 8; //words.length //4

for (let i = 0; i < words.length; i += group_size) {
groups.push(words.slice(i, i + group_size));
Expand Down Expand Up @@ -3167,6 +3182,31 @@ class CognateAnalysisModal extends React.Component {
}
}

async getResultData() {
const {
data: {
suggestion_list,
perspective_name_list,
transcription_count
}
} = await client.query({
query: getResultSuggestions,
variables: { resultFile: this.props.resultFile }
});

this.setState({
suggestion_list,
perspective_name_list,
transcription_count,
dictionary_count: perspective_name_list.length,
suggestion_field_id: this.state.groupFieldIdStr.split(','),
...this.handleSuggestionResult({ suggestion_list }),
cleanResult: false,
computing: false,
result: ""
});
}

render() {
if (!this.state.initialized) {
return (
Expand All @@ -3176,7 +3216,12 @@ class CognateAnalysisModal extends React.Component {
);
}

const { mode } = this.props;
const { mode, resultFile } = this.props;
const viewMode = (mode === "view_suggestions");

if (viewMode && resultFile) {
getResultData();
}

const {
computing,
Expand Down Expand Up @@ -3215,7 +3260,7 @@ class CognateAnalysisModal extends React.Component {
<div>
<Modal
onKeyDown = { e => {
if (e.key === 'Enter' && !disabledCompute) this.handleCreate(); }}
if (e.key === 'Enter' && !disabledCompute && !viewMode) this.handleCreate(); }}
tabIndex = "0"
closeIcon
onClose={ () => {
Expand Down Expand Up @@ -3251,45 +3296,51 @@ class CognateAnalysisModal extends React.Component {
? this.context("Neuro cognate suggestions")
: mode === "multi_neuro_suggestions"
? this.context("Neuro cognate multi-language suggestions")
: mode === "view_suggestions"
? this.context("View cognate suggestions")
: this.context("Cognate analysis")}
</Modal.Header>

{ lang_mode === "none" ? this.browse_files_render() : this.language_render(lang_mode === "multi") }

<Modal.Actions>
{ (mode === "neuro_suggestions" || mode === "multi_neuro_suggestions") && computing && (
<Button
content={this.context("Stop")}
onClick={() => {
this.setState({ computing: false });
this.stopMutation();
}}
className="lingvo-button-red"
/>
)}
<Button
content={
computing ? (
<span>
{this.context("Computing")}{status}... <Icon name="spinner" loading />
</span>
) : (
this.context("Compute")
)
}
onClick={this.handleCreate}
disabled={disabledCompute}
className="lingvo-button-violet"
/>
<Button
content={this.context("Close")}
onClick={ () => {
this.setState({ computing: false }, this.props.closeModal);
this.stopMutation();
}}
className="lingvo-button-basic-black"
/>
</Modal.Actions>
{ !viewMode && (
<>
{ lang_mode === "none" ? this.browse_files_render() : this.language_render(lang_mode === "multi") }

<Modal.Actions>
{ (mode === "neuro_suggestions" || mode === "multi_neuro_suggestions") && computing && (
<Button
content={this.context("Stop")}
onClick={() => {
this.setState({ computing: false });
this.stopMutation();
}}
className="lingvo-button-red"
/>
)}
<Button
content={
computing ? (
<span>
{this.context("Computing")}{status}... <Icon name="spinner" loading />
</span>
) : (
this.context("Compute")
)
}
onClick={this.handleCreate}
disabled={disabledCompute}
className="lingvo-button-violet"
/>
<Button
content={this.context("Close")}
onClick={ () => {
this.setState({ computing: false }, this.props.closeModal);
this.stopMutation();
}}
className="lingvo-button-basic-black"
/>
</Modal.Actions>
</>
)}

{ (/swadesh$/.test(mode) || /morphology$/.test(mode) || this.state.library_present
) && this.state.result !== null && ! this.state.cleanResult && (
Expand Down Expand Up @@ -3593,6 +3644,7 @@ CognateAnalysisModal.contextType = TranslationContext;
CognateAnalysisModal.propTypes = {
perspectiveId: PropTypes.array.isRequired,
closeModal: PropTypes.func.isRequired,
resultFile: PropTypes.string,
computeCognateAnalysis: PropTypes.func.isRequired,
computeSwadeshAnalysis: PropTypes.func.isRequired,
computeMorphCognateAnalysis: PropTypes.func.isRequired,
Expand Down
14 changes: 13 additions & 1 deletion src/ducks/cognateAnalysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { combineReducers } from "redux";
export const OPEN_MODAL = "@cognateAnalysis/OPEN_MODAL";
export const CLOSE_MODAL = "@cognateAnalysis/CLOSE_MODAL";

export const openModal = (perspectiveId, mode) => ({ type: OPEN_MODAL, payload: [perspectiveId, mode] });
export const openModal = (perspectiveId, mode) => ({ type: OPEN_MODAL, payload: [perspectiveId, mode, resultFile] });
export const closeModal = () => ({ type: CLOSE_MODAL });

const visible = (state = false, action) => {
Expand Down Expand Up @@ -40,8 +40,20 @@ const mode = (state = null, { type, payload }) => {
}
};

const resultFile = (state = null, { type, payload }) => {
switch (type) {
case OPEN_MODAL:
return payload[2];
case CLOSE_MODAL:
return null;
default:
return state;
}
};

export default combineReducers({
mode,
perspectiveId,
resultFile,
visible
});
4 changes: 2 additions & 2 deletions src/pages/Perspective/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function submitFilter(value, isCaseSens, isRegexp) {
return setFilter({value, isCaseSens, isRegexp});
}

function openCognateAnalysisModal(perspectiveId, mode = "") {
return cognateAnalysisOpenModal(perspectiveId, mode);
function openCognateAnalysisModal(perspectiveId, mode = "", resultFile = null) {
return cognateAnalysisOpenModal(perspectiveId, mode, resultFile);
}

function openPhonemicAnalysisModal(perspectiveId) {
Expand Down
30 changes: 30 additions & 0 deletions src/pages/Suggestions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import { useLocation } from "react-router-dom";
import { openModal as cognateAnalysisOpenModal } from "ducks/cognateAnalysis";
import { matchPath } from "react-router-dom";
import { compose } from "recompose";
import { connect } from "react-redux";

function getSugg(location) {
const match = matchPath(
{
path: "/suggestions/:sugg"
},
location.path
);
return match && match.params && match.params.sugg;
}

const ViewSuggestions = ({ cognateAnalysisOpenModal }) => {
const location = useLocation();
cognateAnalysisOpenModal(null, "view_suggestions", getSugg(location));
return null;
};

const ViewSuggestionsWrapper = compose(
connect(null, dispatch => ({
actions: bindActionCreators({ cognateAnalysisOpenModal }, dispatch)
}))
)(ViewSuggestions);

export default ViewSuggestionsWrapper;

0 comments on commit 694ff9b

Please sign in to comment.