Skip to content

Commit

Permalink
Merge pull request #170 from opencdms/synoptic-form-update
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosato authored Oct 18, 2024
2 parents f2a1c4c + 6d734d7 commit 940877d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 24 deletions.
48 changes: 39 additions & 9 deletions api/fixtures/wx_variable.json
Original file line number Diff line number Diff line change
Expand Up @@ -4115,15 +4115,15 @@
"fields": {
"created_at": "2024-07-26T23:59:28.639Z",
"updated_at": "2024-07-26T23:59:28.639Z",
"variable_type": "Code",
"variable_type": "Numeric",
"symbol": "LOWCLH",
"name": "Lowest Cloud height",
"sampling_operation": null,
"measurement_variable": null,
"unit": null,
"precision": null,
"scale": null,
"code_table": 1600,
"sampling_operation": 1,
"measurement_variable": 27,
"unit": 20,
"precision": 5,
"scale": 0,
"code_table": null,
"color": "#FF0000",
"range_min": null,
"range_max": null,
Expand Down Expand Up @@ -4238,7 +4238,7 @@
"variable_type": "Numeric",
"symbol": "EVAPINI",
"name": "Evaporation Initial (mm.)",
"sampling_operation": 6,
"sampling_operation": 1,
"measurement_variable": 4,
"unit": 2,
"precision": 5,
Expand Down Expand Up @@ -4268,7 +4268,7 @@
"variable_type": "Numeric",
"symbol": "EVAPRES",
"name": "Evaporation Reset (mm.)",
"sampling_operation": 6,
"sampling_operation": 1,
"measurement_variable": 4,
"unit": 2,
"precision": 5,
Expand All @@ -4288,5 +4288,35 @@
"default_representation": "bar",
"synoptic_code_form": null
}
},
{
"model": "wx.variable",
"pk": 4055,
"fields": {
"created_at": "2024-10-18T00:19:02.390Z",
"updated_at": "2024-10-18T00:19:02.390Z",
"variable_type": "Numeric",
"symbol": "PREC24H",
"name": "Precipitation 24 hours",
"sampling_operation": 6,
"measurement_variable": 3,
"unit": 2,
"precision": 4,
"scale": 1,
"code_table": null,
"color": "#FF0000",
"range_min": null,
"range_max": null,
"range_min_hourly": null,
"range_max_hourly": null,
"step": null,
"step_hourly": null,
"persistence": null,
"persistence_hourly": null,
"persistence_window": null,
"persistence_window_hourly": null,
"default_representation": "line",
"synoptic_code_form": "R24R24R24R24"
}
}
]
10 changes: 7 additions & 3 deletions api/wx/templates/wx/data/synop.html
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,13 @@
return
}

const column = this.hotSettings.columns.find(column => column.data == this.validating.column);
if (!this.codedvalues[column.codetable].includes(value)) {
error = `Value ${value} not in dropdown value list`;
this.addErrorMessage(this.validating.row, this.validating.column, error);
callback(false);
}

const column_data = this.hotSettings.columns.find(column => column.data == this.validating.column)
if(column_data) {
const exists = column_data.source.find(v => v == value)
Expand Down Expand Up @@ -527,16 +534,13 @@
return
}


const ranges = this.columnRanges[this.validating.column];


if (ranges == null){
callback(true);
return
}


const isValid = ranges.min <= numValue && numValue <= ranges.max;
if (!isValid){
error = `Value must be between ${ranges.min} and ${ranges.max}.`;
Expand Down
50 changes: 38 additions & 12 deletions api/wx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7184,7 +7184,7 @@ def get_synop_table_config():
'CLDTOT', 'WNDDIR', 'WNDSPD', 'TEMP', 'TDEWPNT', 'TEMPWB',
'RH', 'PRESSTN', 'PRESSEA', 'PRECSLR', 'PRECDUR', 'PRSWX',
'W1', 'W2', 'Nh', 'CL', 'CM', 'CH', 'STSKY',
'DL', 'DM', 'DH', 'TEMPMIN', 'TEMPMAX', 'N1', 'C1', 'hh1',
'DL', 'DM', 'DH', 'TEMPMAX', 'TEMPMIN', 'PREC24H', 'N1', 'C1', 'hh1',
'N2', 'C2', 'hh2', 'N3', 'C3', 'hh3', 'N4', 'C4', 'hh4', 'SpPhenom'
]

Expand Down Expand Up @@ -7537,7 +7537,7 @@ def get_synop_form_config():
],
["Land Station-no distinction AAXX", "GGggYYGG", "iW", "IIiii", "iR", "iX", "h", "(VV) VV", "N",
"ddd dd", "(fmfm) f f", "1sn", "T'T' TTT", "2sn", "T'dT'd Td TdTd", "UUU", "",
"3", "POPOPOPO", "4", "PHPHPHPH PPPP", "6", "RRR", "tR", "7", "ww", "W1", "W2", "8", "Nh", "CL",
"3", "POPOPOPO", "4", "PHPHPHPH PPPP", "6", "RRR", "Tr", "7", "ww", "W1", "W2", "8", "Nh", "CL",
"CM", "CH", "333", "0", "CS", "DL", "DM", "DH", "1sn", "TXTXTX", "2sn", "TnTnTn", "5j1",
"P24P24P24", "7", "R24R24R24R24", "8", "NS", "C", "hShS", "8", "NS", "C", "hShS", "8", "NS",
"C", "hShS", "8", "NS", "C", "hShS", "9SPSPsPsP", "", ""
Expand Down Expand Up @@ -7674,6 +7674,30 @@ def windDirToCode(wind_dir: float):
wind_dir_code = str(wind_dir_code).zfill(2)
return wind_dir_code

def lowestCloutHightToCode(lowest_ch: float):
if lowest_ch is None or str(lowest_ch)==str(settings.MISSING_VALUE) :
return '/'
elif 0 <= lowest_ch < 50:
return 0
elif 50 <= lowest_ch < 100:
return 1
elif 100 <= lowest_ch < 200:
return 2
elif 200 <= lowest_ch < 300:
return 3
elif 300 <= lowest_ch < 600:
return 4
elif 600 <= lowest_ch < 1000:
return 5
elif 1000 <= lowest_ch < 1500:
return 6
elif 1500 <= lowest_ch < 2000:
return 7
elif 2000 <= lowest_ch < 2500:
return 8
elif 2500 <= lowest_ch:
return 9

def reinfallToCode(rainfall:float):
# Rainfall in mm.
if rainfall is None or rainfall < 0:
Expand Down Expand Up @@ -7705,7 +7729,7 @@ def reinfall24hToCode(rainfall:float):
return '9998'

def precdurCodeToValue(code: str):
print(code)
# This dictionary must match WMO vlues for code 4019
code_table = {
'1': 6,
'2': 12,
Expand All @@ -7719,8 +7743,6 @@ def precdurCodeToValue(code: str):
}
if code not in code_table.keys():
return None
print(code_table[code])

return code_table[code]

def reinfallLast24h(curr_datetime:datetime, rainfall_data:list, rainfall_dur_data:list ):
Expand Down Expand Up @@ -7794,7 +7816,7 @@ def reinfallLast24h(curr_datetime:datetime, rainfall_data:list, rainfall_dur_dat
{'type': 'Const', 'ref': station.synoptic_type}, {'type': 'Func', 'ref': 'DateHour'},
{'type': 'Var', 'ref': 'WINDINDR'}, {'type': 'Const', 'ref': station.synoptic_code},
{'type': 'Var', 'ref': 'PRECIND'}, {'type': 'Var', 'ref': 'STATIND'},
{'type': 'Var', 'ref': 'LOWCLH'}, {'type': 'Var', 'ref': 'VISBY'}, {'type': 'Var', 'ref': 'CLDTOT'},
{'type': 'SpVar', 'ref': 'LOWCLH'}, {'type': 'Var', 'ref': 'VISBY'}, {'type': 'Var', 'ref': 'CLDTOT'},
{'type': 'SpVar', 'ref': 'WNDDIR'}, {'type': 'SpVar', 'ref': 'WNDSPD'},
{'type': '1sn', 'ref': 'TEMP'}, {'type': 'SpVar', 'ref': 'TEMP'},
{'type': '2sn', 'ref': 'TDEWPNT'},
Expand All @@ -7814,11 +7836,12 @@ def reinfallLast24h(curr_datetime:datetime, rainfall_data:list, rainfall_dur_dat
{'type': 'Const', 'ref': 0},
{'type': 'Var', 'ref': 'STSKY'},
{'type': 'Var', 'ref': 'DL'}, {'type': 'Var', 'ref': 'DM'}, {'type': 'Var', 'ref': 'DH'},
{'type': '1sn', 'ref': 'TEMPMIN'}, {'type': 'SpVar', 'ref': 'TEMPMIN'},
{'type': '2sn', 'ref': 'TEMPMAX'}, {'type': 'SpVar', 'ref': 'TEMPMAX'},
{'type': '1sn', 'ref': 'TEMPMAX'}, {'type': 'SpVar', 'ref': 'TEMPMAX'},
{'type': '2sn', 'ref': 'TEMPMIN'}, {'type': 'SpVar', 'ref': 'TEMPMIN'},
{'type': '5j1', 'ref': None}, {'type': 'Func', 'ref': 'BarometricChange'},
{'type': 'Const', 'ref': 7},
{'type': 'Func', 'ref': '24hRainfall'},
# {'type': 'Func', 'ref': '24hRainfall'},
{'type': 'SpVar', 'ref': 'PREC24H'},
{'type': 'Const', 'ref': 8},
{'type': 'Var', 'ref': 'N1'}, {'type': 'Var', 'ref': 'C1'}, {'type': 'Var', 'ref': 'hh1'},
{'type': 'Const', 'ref': 8},
Expand Down Expand Up @@ -7926,7 +7949,10 @@ def reinfallLast24h(curr_datetime:datetime, rainfall_data:list, rainfall_dur_dat
value = windSpeedToCode(value)
elif variable.symbol=='PRECSLR':
value = reinfallToCode(value)

elif variable.symbol=='PREC24H':
value = reinfall24hToCode(value)
elif variable.symbol=='LOWCLH':
value = lowestCloutHightToCode(value)
elif column_type=='Func':
if reference[j]['ref']=='DateHour':
value=dayhour
Expand All @@ -7938,8 +7964,8 @@ def reinfallLast24h(curr_datetime:datetime, rainfall_data:list, rainfall_dur_dat
value = airTempCalc(dew_point)
elif reference[j]['ref']=='BarometricChange':
value = f"{abs(barometric_change_24h):04}" if barometric_change_24h is not None else None
elif reference[j]['ref']=='24hRainfall':
value = reinfallLast24h(datetime_row, rainfall_data, rainfall_dur_data) if i in [0,6,12,18] else None
# elif reference[j]['ref']=='24hRainfall':
# value = reinfallLast24h(datetime_row, rainfall_data, rainfall_dur_data) if i in [0,6,12,18] else None
else:
value = 'Func'
elif column_type=='Text':
Expand Down

0 comments on commit 940877d

Please sign in to comment.