Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bi 1817 #321

Merged
merged 3 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/breeding-insight/dao/ExperimentDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
* limitations under the License.
*/

import { Response} from "@/breeding-insight/model/BiResponse";
import {BiResponse, Response} from "@/breeding-insight/model/BiResponse";
import * as api from "@/util/api";
import {Result, ResultGenerator} from "@/breeding-insight/model/Result";
import {Trial} from "@/breeding-insight/model/Trial.ts";
import * as UUID from "uuid";
import {PaginationQuery} from "@/breeding-insight/model/PaginationQuery";
import {DatasetModel} from "@/breeding-insight/model/DatasetModel";

export class ExperimentDAO {

Expand All @@ -37,4 +40,25 @@ export class ExperimentDAO {
return ResultGenerator.err(error);
}
}
static getDatasetById(programId: string, experimentId: string, datasetId: string, stats: boolean): Promise<Result<Error, DatasetModel>> {
const config: any = {};
config.url = `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/experiments/${experimentId}/dataset/${datasetId}`;
config.method = 'get';
config.programId = programId;
config.experimentId = experimentId;
config.datasetId = datasetId;
config.params = {
stat : stats,
};
return new Promise<Result<Error, DatasetModel>>(((resolve, reject) => {
api.call(config)
.then((response: any) => {
const biResponse = new BiResponse(response.data);
resolve(biResponse);
}).catch((error) => {
reject(error);
})
}))
}

}
61 changes: 61 additions & 0 deletions src/breeding-insight/model/DatasetModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {Observation} from "@/breeding-insight/model/Observation";
import {ObservationUnit} from "@/breeding-insight/model/ObservationUnit";
import {ObservationVariable} from "@/breeding-insight/model/ObservationVariable";

export class DatasetModel {
id?: string;
experimentId?: string;
additionalInfo?: any;
data?: Observation[];
observationUnits?: ObservationUnit[];
observationVariables?: ObservationVariable[];


constructor(id?: string,
experimentId?: string,
additionalInfo?: any,
data?: Observation[],
observationUnits?: ObservationUnit[],
observationVariables?: ObservationVariable[]
) {
this.id = id;
this.experimentId = experimentId;
this.additionalInfo = additionalInfo;
this.data = data;
this.observationUnits = observationUnits;
this.observationVariables = observationVariables;
}

static assign(dataset: DatasetModel): DatasetModel {

return new DatasetModel(
dataset.id,
dataset.experimentId,
dataset.additionalInfo,
dataset.data,
dataset.observationUnits
);
}

equals(dataset?: DatasetModel): boolean {
if (!dataset) {return false;}
return (this.id === dataset.id)
}
}
9 changes: 9 additions & 0 deletions src/breeding-insight/service/ExperimentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import {ExperimentDAO} from "@/breeding-insight/dao/ExperimentDAO";
import {Trial} from "@/breeding-insight/model/Trial.ts";
import {Result, ResultGenerator} from "@/breeding-insight/model/Result";
import {DatasetModel} from "@/breeding-insight/model/DatasetModel";

export class ExperimentService {

Expand All @@ -27,4 +28,12 @@ export class ExperimentService {
}
return await ExperimentDAO.getSingleExperiment(programId, experimentId, stats);
}

static async getDatasetModel(programId: string, experimentId: string, datasetId: string): Promise<Result<Error, DatasetModel>> {
if (!programId) {
return ResultGenerator.err(new Error('Missing or invalid program id'));
}
return await ExperimentDAO.getDatasetById(programId,experimentId, datasetId, true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
>
<template #form>
<div class="columns mb-4">
<!-- Dataset Select -->
<!-- DatasetModel Select -->
<div class="column control">
<div class="field">
<label
class="label"
v-bind:for="`dataset-select-${trialDbId}`"
><span>Dataset</span></label>
><span>DatasetModel</span></label>
<div class="control">
<div class="select">
<select
Expand Down
20 changes: 19 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import BrapiAuthorize from '@/views/BrAPI/BrapiAuthorize.vue'
import BrAPIInfo from '@/views/BrAPI/BrAPIInfo.vue'
import ProgramManagement from '@/views/program/ProgramManagement.vue'
import ExperimentDetails from "@/views/experiments-and-observations/ExperimentDetails";
import Dataset from "@/views/import/Dataset.vue";
import StudiesList from "@/views/trials-and-studies/StudiesList.vue";
import ObservationsList from '@/views/observations/ObservationsList.vue';
import AdminProgramManagement from '@/views/admin/AdminProgramManagement.vue'
Expand Down Expand Up @@ -366,7 +367,24 @@ const routes = [
layout: layouts.userSideBar
},
component: ExperimentDetails,
beforeEnter: processProgramNavigation
redirect: (to: Route) => ({name: 'experiment_obs_dataset', params: {datasetId: 'observation', programId: to.params.programId, experimentId: to.params.experimentId}}),
beforeEnter: processProgramNavigation,
children: [
{
path: 'dataset/:datasetId',
name: 'experiment_obs_dataset',
meta: {
title: 'Observation Dataset',
layout: layouts.userSideBar
},
component: Dataset,
props: (route: any) => {
return ({
...route.params
})
}
}
]
},
{
path: '/programs/:programId/import',
Expand Down
19 changes: 19 additions & 0 deletions src/views/experiments-and-observations/ExperimentDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@
</div>

</div>
<section>
<nav class="tabs is-boxed">
<ul>
<router-link
v-bind:to="{name: 'experiment_obs_dataset', params: {programId: activeProgram.id, experimentId: experimentUUID, datasetId: 'observation'}}"
tag="li" active-class="is-active">
<a>Observation DatasetModel</a>
</router-link>
<!--TODO: Will need to loop through a list of datasets and add a tab for each.-->
</ul>
</nav>
</section>
<div class="tab-content">
<router-view
@show-success-notification="$emit('show-success-notification', $event)"
@show-info-notification="$emit('show-info-notification', $event)"
@show-error-notification="$emit('show-error-notification', $event)"
/>
</div>
</div>
</template>

Expand Down
146 changes: 146 additions & 0 deletions src/views/import/Dataset.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<!--
- See the NOTICE file distributed with this work for additional information
- regarding copyright ownership.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->

<template>
<div id="data_set">
<div v-if="loading">
loading dataset...
<progress class="progress is-normal" max="80"></progress>
</div>
<article
v-if="!loading"
class="message is-success"
>
<div class="message-body">
<div class="columns is-multiline">
<div class="column is-one-fifth">
<div class="has-text-right">
<b>Observation unit: </b> <span style="width: 30px;" class="is-inline-block has-text-left">{{ observationUnit }}</span><br>
<b>Phenotypes: </b> <span style="width: 30px;" class="is-inline-block has-text-left">{{ phenotypesCount }}</span><br>
<b>Total observations: </b> <span style="width: 30px;" class="is-inline-block has-text-left">{{ totalObservationsCount }}</span><br>
<b>Observations with data: </b> <span style="width: 30px;" class="is-inline-block has-text-left">{{ observationsWithData }}</span><br>
<b>Observations without data: </b> <span style="width: 30px;" class="is-inline-block has-text-left">{{ observationsWithoutData }}</span><br>
</div>
</div>
</div>
</div>
</article>
</div>
</template>

<script lang="ts">
import {Component, Prop, Vue, Watch} from 'vue-property-decorator'
import ProgramsBase from "@/components/program/ProgramsBase.vue";
import {Result} from "@/breeding-insight/model/Result";
import {DatasetModel} from "@/breeding-insight/model/DatasetModel";
import {ExperimentService} from "@/breeding-insight/service/ExperimentService";
import {Program} from "@/breeding-insight/model/Program";
import {mapGetters} from "vuex";

@Component({
computed: {
...mapGetters([
'activeProgram'
])
}
})
export default class Dataset extends ProgramsBase {
private activeProgram: Program;
private datasetModel: DatasetModel;
private experiment: Experiment;
private loading: boolean = true;
private resultDatasetId: string;


mounted () {
this.getDatasetModelAndExperiment();
}

@Prop()
private datasetId?: string;

get experimentUUID(): string {
return this.$route.params.experimentId;
}

get observationUnit(): string{
let ou = "NA"
if(this.experiment && this.experiment.additionalInfo && this.experiment.additionalInfo.defaultObservationLevel){
ou = this.experiment.additionalInfo.defaultObservationLevel;
}
return ou;
}

get phenotypesCount(): number{
let count = 0;

if(this.datasetModel && this.datasetModel.observationVariables){
count = this.datasetModel.observationVariables.length;
}
return count
}

// Total observations
get totalObservationsCount(): number {
let count = 0;

if(this.datasetModel && this.datasetModel.observationUnits){
let ouCount = this.datasetModel.observationUnits.length;
count = ouCount * this.phenotypesCount;
}
return count
}

// Observations with data
get observationsWithData(): number {
let count = 0;
if(this.datasetModel && this.datasetModel.data){
count = this.datasetModel.data.length;
}
return count
}

// Observations without data
get observationsWithoutData(): number {
return this.totalObservationsCount-this.observationsWithData
}

@Watch('$route')
async getDatasetModelAndExperiment () {
this.loading = true;
let experimentResult = await ExperimentService.getSingleExperiment(this.activeProgram!.id!, this.experimentUUID,false);
this.experiment = experimentResult.value;

if( this.datasetId==='observation'){
this.resultDatasetId = this.experiment.additionalInfo.observationDatasetId;
}
else{
this.resultDatasetId = this.datasetId;
}
try {
const response: Result<Error, DatasetModel> = await ExperimentService.getDatasetModel(this.activeProgram!.id!, this.experimentUUID, this.resultDatasetId);
this.datasetModel = response.result;
} catch (err) {
// Display error that experiment cannot be loaded
this.$emit('show-error-notification', 'Error while trying to load data set' + err.message());
throw err;
} finally {
this.loading = false;
}
}
}
</script>