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

ex_problemsanddangers.py example does not work, reference WIP PR #14 #15

Open
Jakidxav opened this issue Mar 8, 2021 · 0 comments
Open
Assignees

Comments

@Jakidxav
Copy link
Contributor

Jakidxav commented Mar 8, 2021

We can begin to examine the error by running:

python3 ex_problemsanddangers.py

We get back:

Traceback (most recent call last):
File "ex_problemsanddangers.py", line 41, in <module>
forecast_problems += gp.get_forecasted_problems(region_ids, from_date, to_date, lang_key=1)
File "/home/jakidxav/varsomdata/varsomdata/getproblems.py", line 206, in get_forecasted_problems
problems_from='Forecast', lang_key=lang_key)
File "/home/jakidxav/varsomdata/varsomdata/getproblems.py", line 272, in get_all_problems
problem_warn = _map_warning_to_problem(warnings)
File "/home/jakidxav/varsomdata/varsomdata/getproblems.py", line 145, in _map_warning_to_problem
region_id = w.region_id
AttributeError: 'AvalancheDanger' object has no attribute 'region_id'

The problem is with the _map_warning_to_problem() method. First, you pass in a list of warnings which contain AvalancheDanger objects. A typical AvalancheDanger object has the following fields:

{'metadata': {}, 'region_regobs_id': 133, 'region_name': 'Salten', 'data_table': 'Forecast API', 'date': datetime.date(2014, 11, 10), 'danger_level': 0, 'danger_level_name': None, 'avalanche_problems': [], 'main_message_no': 'Ikke vurdert', 'main_message_en': None, 'mountain_weather': None, 'source': 'Forecast', 'nick': None, 'avalanche_nowcast': None, 'avalanche_forecast': None, 'url': 'http://www.varsom.no/snoskredvarsling/varsel/Salten/2014-11-10'}

So we see that there is no region_id attribute which makes the program stop. I fixed that and moved on, but a similar error occurs when trying to access the publish_time attribute. Again, we can change this to date as there is no publish_time attribute. This may not be the right thing to do, however.

These changes still causes issues, this time with iterating over a list of AvalancheProblem objects in line 149. One such object looks like this:

{'metadata': {}, 'region_regobs_id': 132, 'region_name': 'Hallingdal', 'date': datetime.date(2014, 12, 2), 'order': 1, 'cause_tid': 11, 'cause_name': 'Nedsnødd eller nedføyket overflaterim', 'source': 'Forecast', 'problem': 'Vedvarende svakt lag (flakskred)', 'problem_tid': 30, 'main_cause': None, 'aval_type': 'Tørre flakskred', 'aval_type_tid': 20, 'aval_size': '2 - Middels', 'aval_size_tid': 2, 'aval_trigger': 'Liten tilleggsbelastning', 'aval_trigger_tid': 21, 'aval_distribution': 'Få bratte heng', 'aval_probability': 'Mulig', 'danger_level': 2, 'danger_level_name': '2 Moderat', 'url': 'http://www.varsom.no/snoskredvarsling/varsel/Hallingdal/2014-12-02', 'regobs_table': 'AvalancheWarnProblem', 'nick_name': 'birgitrustad', 'lang_key': 1}

The method is trying to access avalanche_problem_id, aval_cause_name, aval_cause_id, destructive_size_ext_name, etc when they do not exist.

I believe I have located the issue in the file varsomdata/getforcastapi.py in the method get_avalanche_warnings_deprecated. I think it has to do with an error where get_avalanche_warnings_deprecated still returns warnings that have None in the avalanche problems. See first printout in getproblems.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants