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

Bug/inferred metric #615

Merged
merged 3 commits into from
Dec 4, 2024
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
33 changes: 31 additions & 2 deletions src/app/global/mixins/reach-api-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,41 @@ export const reachApiHelper = {
// these take just the correlation status object
displayGaugeCorrelationLatestReadingTime(status) {
if (status && status.latestReading) {
const now = new Date();
const readingTime = new Date(status.latestReading.dateTime);
return humanReadable(now.getTime() - readingTime.getTime())
return this.timeSince(readingTime);
}
return '';
},
// returns the metric from correlationDetails if it
// is set; if not, infers by checking gaugeInfo's latest
// readings and defaulting to CFS if available
getCorrelationMetric(gauge) {
if (gauge.correlationDetails && gauge.correlationDetails.metric) {
return gauge.correlationDetails.metric;
} else {
if (gauge.gaugeInfo.latestFlowReading) {
return this.correlationMetrics.cfs.key;
} else if (gauge.gaugeInfo.latestStageReading) {
return this.correlationMetrics.levelFT.key;
}
}
return null;
},
// returns latest reading from status if corrDetails are set
// otherwise, returns from gaugeInfo, defaulting to cfs
// if available and otherwise returning stage or null
getLatestReading(gauge) {
if (gauge.status) {
return gauge.status.latestReading;
} else {
return gauge.gaugeInfo.latestFlowReading ||
gauge.gaugeInfo.latestStageReading || null;
}
},
timeSince(dateTime) {
const now = new Date();
return humanReadable(now.getTime() - dateTime.getTime());
},
cssClassForGaugeCorrelation(status) {
if (status && status.status) {
return status.status; // TODO: not 100% sure if this works atm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
type: String,
required: false,
default: 'week',
validator: val => ['24h', 'week', 'year'].indexOf(val) > -1
validator: val => ['24h', 'week', 'month', 'year'].indexOf(val) > -1
},
readings: {
type: Array,
Expand Down
26 changes: 19 additions & 7 deletions src/app/views/river-detail/components/flow-tab/flow-tab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
Difficulty at this level
</template>
</div>
<div v-if="gauge.status" :class="`gauge-reading background`">
{{ gauge.status.latestReading.value }} {{ correlationMetrics[gauge.status.metric].unit }}
@ {{ formatDate(new Date(gauge.status.latestReading.dateTime)) }}
<div v-if="displayLatestReading(gauge)" :class="`gauge-reading background`">
{{ displayLatestReading(gauge) }}
</div>
<div v-if="gauge.correlationDetails" class="gauge-range">
{{ gauge.correlationDetails.beginLowRunnable }} - {{ gauge.correlationDetails.endHighRunnable }}
Expand Down Expand Up @@ -76,8 +75,6 @@
:timeScale="gauge.historyTimeScale"
class="mb-md"
:metric="correlationMetrics[gauge.requestedMetric]"
:current="gauge.status.latestReading.value"

/>
</div>
</div>
Expand Down Expand Up @@ -277,9 +274,13 @@ export default {
let correlations = [];
if (reachDetail?.detail?.correlations) {
correlations = reachDetail?.detail?.correlations.map(c => {
// if metric isn't set (and corrDetails isn't set),
// infer default metric based on what data is available, defaulting to CFS
const requestedMetric = this.getCorrelationMetric(c);

return {
...c,
requestedMetric: c.correlationDetails?.metric,
requestedMetric: requestedMetric,
historyTimeScale: 'week',
readings: [],
loading: true
Expand Down Expand Up @@ -309,14 +310,25 @@ export default {
return ('too-hi')
}
},
displayLatestReading(gauge) {
if (gauge.status) {
return `${gauge.status.latestReading.value} ${this.correlationMetrics[gauge.status.metric].unit}` +
` @ ${this.formatDate(new Date(gauge.status.latestReading.dateTime))}`;
} else if (gauge.readings && gauge.readings.length) {
const reading = gauge.readings[0];
return `${reading.value} ${this.correlationMetrics[gauge.requestedMetric].unit}` +
` @ ${this.formatDate(new Date(reading.dateTime))}`;
}
return null;
},
correlationMatchesMetric(gauge) {
return gauge && gauge.correlationDetails &&
gauge.correlationDetails.metric === gauge.requestedMetric;
},
async getReadings(gauge) {
gauge.loading = true;
gauge.readings = await gaugeClient.gaugeReadingsHistory.query({
desiredMetric: gauge.requestedMetric || this.correlationMetrics.cfs.key,
desiredMetric: gauge.requestedMetric,
timePeriod: gauge.historyTimeScale || '24h',
gaugeSource: gauge.gaugeInfo.gaugeSource,
gaugeSourceIdentifier: gauge.gaugeInfo.gaugeSourceIdentifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@
{{ correlationMetrics[gaugeCorrelation.correlationDetails.data.metric].unit }}
</td>
</tr>
<tr v-if="gaugeCorrelation.status">
<tr v-if="gaugeCorrelation && getLatestReading(gaugeCorrelation)">
<td>
Flow Rate
as of {{ displayGaugeCorrelationLatestReadingTime(gaugeCorrelation.status) }}
as of {{ displayLatestReadingTime }}
</td>
<td class="river-flow-rate">
{{ gaugeCorrelation.status.latestReading.value }} {{ correlationMetrics[gaugeCorrelation.status.metric].unit }}
{{ getLatestReading(gaugeCorrelation).value }} {{ correlationMetrics[getCorrelationMetric(gaugeCorrelation)].unit }}
<cv-tag
v-if="adjustedReachDifficulty(gaugeCorrelation)"
kind="cool-gray"
:label="adjustedReachDifficulty(gaugeCorrelation)"
/>
<cv-tag
v-if="gaugeCorrelation.status.status"
v-if="gaugeCorrelation.status && gaugeCorrelation.status.status"
:class="gaugeCorrelation.status.status"
:label="gaugeCorrelation.status.status.replace('-', ' ').replace('migration', '')"
/> <!-- TODO: reference to "migration" above handles existing legacy migration-runnable data -->
Expand Down Expand Up @@ -161,6 +161,10 @@ export default {
}
return null;
},
displayLatestReadingTime() {
const readingTime = new Date(this.getLatestReading(this.gaugeCorrelation).dateTime);
return this.timeSince(readingTime);
},
/**
* Event date or null
*/
Expand Down
4 changes: 2 additions & 2 deletions src/app/views/river-index/rivers-by-state.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
<tr v-for="reach in reaches" :key="reach.id" :class="`${cssClassForGaugeCorrelation(reach.correlation)} reach`" @click="$router.push(`/river-detail/${reach.id}/main`)">
<td>
<strong>
{{ [reach.river, renderLegacyDifficulty(reach.class)].join(" - ") }}
{{ [reach.river, reach.class].join(" - ") }}
</strong>
<br>
{{ reach.section }}
<span v-if="reach.altname">({{ reach.altname }})</span>
</td>
<td class="reach-flow">
<strong v-if="reach.correlation && reach.correlation.status">
<strong v-if="reach.correlation">
{{ reach.correlation.latestReading.value }} {{ correlationMetrics[reach.correlation.metric].unit }}
</strong>
</td>
Expand Down
Loading