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 2 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
5 changes: 5 additions & 0 deletions src/assets/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -900,3 +900,8 @@ tr:nth-child(odd) td.db-filled {
display: block;
}
}

.detail {
background-color:AntiqueWhite;

}
mlm483 marked this conversation as resolved.
Show resolved Hide resolved
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 {Dataset} from "@/breeding-insight/model/Dataset";

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, Dataset>> {
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, Dataset>>(((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/Dataset.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 Dataset {
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: Dataset): Dataset {

return new Dataset(
dataSet.id,
dataSet.experimentId,
dataSet.additionalInfo,
dataSet.data,
dataSet.observationUnits
);
}

equals(dataSet?: Dataset): 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 {Dataset} from "@/breeding-insight/model/Dataset";

export class ExperimentService {

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

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

}
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 Dataset</a>
</router-link>
<!--TODO &#45;&#45; Will need to loop through a list of datasets and add a tab for each.-->
mlm483 marked this conversation as resolved.
Show resolved Hide resolved
</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
163 changes: 163 additions & 0 deletions src/views/import/DataSet.vue
mlm483 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<!--
- 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...
</div>
<div v-if="!loading" class="detail">
<div class="columns is-multiline is-align-items-stretch mt-4">
<article class="column ">
<section>
<ul style="list-style-type: none;">
<li><b>Observation unit: </b> {{ observationUnit }}</li>
<li><b>phenotypes: </b> {{ phenotypesCount }}</li>
davedrp marked this conversation as resolved.
Show resolved Hide resolved
<li><b>Total observations: </b> {{ totalObservationsCount }}</li>
<li><b>Observations with data: </b> {{ observationsWithData }}</li>
<li><b>Observations without data: </b> {{ observationsWithoutData }}</li>
</ul>
</section>
</article>
mlm483 marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
</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 {Dataset} from "@/breeding-insight/model/Dataset";
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 dataSet: Dataset;
private experiment: Experiment;
private loading: boolean = true;
private resultDatasetId: string;


mounted () {
this.getDataSetAndExperiment();
}

@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(): string{
let count = 'N/A';

if(this.dataSet && this.dataSet.observationVariables){
let nCount = this.dataSet.observationVariables.length;
count = String(nCount);
}
return count
}

// Total observations
get totalObservationsCount(): string {
let count = 'N/A';

if(this.dataSet && this.dataSet.observationUnits){
let ouCount = this.dataSet.observationUnits.length;
if(this.dataSet && this.dataSet.observationVariables){
let oVarCount = this.dataSet.observationVariables.length;
count = String(ouCount * oVarCount);
}
}
return count
}

// Observations with data
get observationsWithData(): string {
let count = 'N/A';

if(this.dataSet && this.dataSet.data){
let nCount = this.dataSet.data.length;
count = String(nCount);
}
return count
}

// Observations without data
get observationsWithoutData(): string {
let count = 'N/A';

if(this.dataSet && this.dataSet.observationUnits){
let ouCount = this.dataSet.observationUnits.length;
if(this.dataSet && this.dataSet.observationVariables){
let oVarCount = this.dataSet.observationVariables.length;
let totalObs = (ouCount * oVarCount);
if(this.dataSet && this.dataSet.data){
let obsWithData = this.dataSet.data.length;
count = String(totalObs-obsWithData);
}
}
}

return count
}

@Watch('$route')
async getDataSetAndExperiment () {
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, DataSet> = await ExperimentService.getDataSet(this.activeProgram!.id!, this.experimentUUID, this.resultDatasetId);
this.dataSet = 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>