FAI-CIVL / FAI-Airscore

AirScore - online paragliding / hanggliding GAP-based scoring software.
https://airscore.cc/
GNU General Public License v3.0
13 stars 17 forks source link

Type mismatch for * operator, scoring. #205

Closed philderbeast closed 3 years ago

philderbeast commented 3 years ago

On branch flare_timing_yaml at 1152378aabeb6e6459edff6f7333a3e7edf62acb, scoring tasks 2, 3, 4 or 5 of Dalby 2017 errors with:

# POST http://localhost:5000/users/_score_task/16 500 (INTERNAL SERVER ERROR)
Traceback (most recent call last):
  File "/home/sid/.local/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/sid/.local/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/home/sid/.local/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/sid/.local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/sid/.local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/sid/.local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/sid/.local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/sid/.local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/sid/.local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/sid/.local/lib/python3.8/site-packages/flask_debugtoolbar/__init__.py", line 125, in dispatch_request
    return view_func(**req.view_args)
  File "/home/sid/.local/lib/python3.8/site-packages/flask_login/utils.py", line 272, in decorated_view
    return func(*args, **kwargs)
  File "/app/airscore/user/views.py", line 1136, in _score_task
    ref_id, filename = task.create_results(data['status'])
  File "/app/airscore/core/task.py", line 670, in create_results
    lib.calculate_results(self)
  File "/app/airscore/core/formulas/gap2016.py", line 153, in calculate_results
    points_weight(task)
  File "/app/airscore/core/formulas/libs/gap.py", line 266, in points_weight
    task.dep_weight = (1 - task.dist_weight) / 8 * 1.4 * formula.lead_factor
TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'

Scoring the 1st task completes without this error. This first task doesn't have leading points.

kuaka commented 3 years ago

@biuti when importing this fsdb file the lead factor is set to null in the DB. I think that this should be set to 0 (there maybe other similar errors on importing a null instead of zero.

kuaka commented 3 years ago

@philderbeast as a work around until the import is fixed, you can go to comp settings -> formula -> advanced and set the lead factor to 0 and save. There is a bug here that it shows 1.00 even after saving but the DB gets updated to 0. then hopefully the scoring should work. opened issue #206

philderbeast commented 3 years ago

@philderbeast as a work around until the import is fixed, you can go to comp settings -> formula -> advanced and set the lead factor to 0 and save.

That works thanks @kuaka.

biuti commented 3 years ago

the formula is created like this: formula.lead_factor = ( None if form.get('use_leading_points') == '0' else float(form.get('leading_weight_factor') if form.get('leading_weight_factor') else 1) ) So it is set to null when leading points are not used. From FSDB we take Formula for competition and TaskFormula for each task. Probably in that competition they put departure points = off in the competition, that is wrong if you intend to use them even in just one task. We don't have a _leading_weightfactor at task level in database as it should not change during the whole comp. In that FSDB version there isn't at any level anyway as there was no setting for the factor back in 2017. It is quite a strange case that should really never happen if comp setting is done right in FS. We have a lot of parameters set as None when they can be used as a boolean if it should not be used. JTG or SS_interval are some examples. Not sure we want to change this. Probably we can add a check that if at least a task has leading points, then lead factor cannot be None or 0 (should be set to 1). But again, we should set Comp formula with dep = 'leadout' and _leadfactor = 1, and then set dep = 'off' in tasks where they are not used.

kuaka commented 3 years ago

the formula is created like this: formula.lead_factor = ( None if form.get('use_leading_points') == '0' else float(form.get('leading_weight_factor') if form.get('leading_weight_factor') else 1) )

this looks like the creation from the form not the fsdb. Regardless it is strange that we set something to null then in the form display it as 1 (even if it was 0 we displayed it as 1 but in my commit yesterday I fixed that at least). What is displayed on the form should reflect reality especially if there is a chance that the user will not save the form and therefore overwrite the null with the forms default value.. this is likely not to happen with imported comps

So it is set to null when leading points are not used. From FSDB we take Formula for competition and TaskFormula for each task. Probably in that competition they put departure points = off in the competition, that is wrong if you intend to use them even in just one task.

you can see exactly what is was in the FSDB file liked above. Here is an extract:

    <FsScoreFormula id="GAP2016" use_distance_points="1" use_time_points="1" use_departure_points="0" use_leading_points="0" 
    ........

    <FsTask id="1" name="day one" tracklog_folder="day one">
            <FsScoreFormula id="GAP2016" use_distance_points="1" use_time_points="1" use_departure_points="0" use_leading_points="0" 

    .......
     <FsTask id="2" name="day four T2" tracklog_folder="day four">
            <FsScoreFormula id="GAP2016" use_distance_points="1" use_time_points="1" use_departure_points="0" use_leading_points="1"

So they are using leading points for some tasks and not others. Whether it was done 'right' or 'wrong' in FS is moot as FS created this file and FS sets the standard when it comes to FSDB files. If airScore imports it, it should be able to cope with the settings in it. I don't understand why we need to set the leading weight to null if lead points are not used. If lead points are not used then (I hope) the calculation will not run so it could be set to any number, if LP are used then having a null is going to cause this error. proposed solution - set LP weight to 1 when not specified (the form will show 1 anyway.. the form should reflect reality or vice versa) then if LP are used at least airScore will not crash.

biuti commented 3 years ago

defaulted to 1 in database and object. Your commit makes it compatible with older database version. (https://github.com/FAI-CIVL/FAI-Airscore/commit/eb66a069f791271342803895c606bdd8c96a63cc)