Skip to content

Commit

Permalink
Make value for measurement from surface or top as positive
Browse files Browse the repository at this point in the history
  • Loading branch information
meomancer committed Dec 4, 2024
1 parent 0f71083 commit b7ba27b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
9 changes: 5 additions & 4 deletions admin/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from gwml2.models.general import (
Unit, UnitConvertion, UnitGroup, Country, Quantity
)
from gwml2.tasks.data_file_cache.country_recache import (
generate_data_country_cache
)


class UnitConvertionInline(admin.TabularInline):
Expand All @@ -24,4 +21,8 @@ class UnitAdmin(admin.ModelAdmin):
admin.site.register(UnitGroup, UnitGroupAdmin)
admin.site.register(Unit, UnitAdmin)
admin.site.register(Quantity)
admin.site.register(Country)


@admin.register(Country)
class CountryAdmin(admin.ModelAdmin):
list_display = ('name', 'code')
20 changes: 17 additions & 3 deletions static/gwml2/js/measurement-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,11 @@ function getTrendlines(chartData, steps) {
});
return [data, jumps]
} catch (e) {
console.log(e)
return [[], []]
}
}

function renderMeasurementChart(identifier, chart, data, xLabel, yLabel, stepTrenlineData, toggleSeries, onChartClicked, title = '') {
function renderMeasurementChart(identifier, chart, data, xLabel, yLabel, stepTrenlineData, toggleSeries, onChartClicked, title = '', reverse = false, unit = '') {
switch (identifier) {
case 'WellLevelMeasurement':
case 'level_measurement':
Expand Down Expand Up @@ -236,6 +235,12 @@ function renderMeasurementChart(identifier, chart, data, xLabel, yLabel, stepTre
yAxis: {
title: {
text: yLabel
},
labels: {
formatter: function () {
const val = reverse ? Math.abs(this.value) : this.value;
return `${val} ${unit}`;
}
}
},
xAxis: {
Expand Down Expand Up @@ -280,6 +285,12 @@ function renderMeasurementChart(identifier, chart, data, xLabel, yLabel, stepTre
dataGrouping: { groupPixelWidth: 50, units: [['hour', [4]], ['day', [1]], ['week', [1, 2]], ['month', [1]]] }
}
},
tooltip: {
pointFormatter: function () {
const val = reverse ? Math.abs(this.y) : this.y;
return `<span style="color:${this.color}">●</span> ${this.series.name}: <b>${parseFloat(val.toFixed(this.series.tooltipOptions.valueDecimals))} ${unit}</b><br/>`;
}
},
series: [
{
id: 'value',
Expand Down Expand Up @@ -615,6 +626,7 @@ let MeasurementChartObj = function (
}

let title = getParamGroup(this.parameterTo)
const reverse = [FROM_TOP_WELL, FROM_GROUND_LEVEL].includes(this.parameterTo);
this.chart = renderMeasurementChart(
this.identifier, this.chart,
cleanData[this.parameterTo],
Expand All @@ -625,7 +637,9 @@ let MeasurementChartObj = function (
onNewStep(date.getTime());
}
},
title
title,
reverse,
this.unitTo
)
this.$loading.hide();
};
Expand Down
2 changes: 1 addition & 1 deletion templates/groundwater_form/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ <h5>{% trans "Well and Monitoring Data Record" %}</h5>
<script src="{% static "js/highcharts/9.1.2/stock/indicators/indicators.js" %}"></script>
<script src="{% static "js/highcharts/9.1.2/stock/indicators/trendline.js" %}"></script>
<script src="{% static 'gwml2/js/unit-converter.js' %}"></script>
<script src="{% static 'gwml2/js/measurement-chart.js' %}?v=1"></script>
<script src="{% static 'gwml2/js/measurement-chart.js' %}?v=2"></script>
<script src="{% static 'gwml2/js/utilities.js' %}"></script>
<script src="{% static 'gwml2/js/scripts.js' %}"></script>
<script src="{% static 'gwml2/js/many-to-many-script.js' %}"></script>
Expand Down
2 changes: 1 addition & 1 deletion templates/plugins/measurements_chart_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>

<script src="{% static 'gwml2/js/unit-converter.js' %}"></script>
<script src="{% static 'gwml2/js/measurement-chart.js' %}?v=1"></script>
<script src="{% static 'gwml2/js/measurement-chart.js' %}?v=2"></script>
</head>
<body>
<script>
Expand Down

0 comments on commit b7ba27b

Please sign in to comment.