Open mammatus95 opened 2 years ago
*** backend/PythonPackage/pywetterturnier/judgingclass20021206.py 2022-01-15 10:43:55.000000000 +0100
--- backend_old/PythonPackage/pywetterturnier/judgingclass20021206.py 2022-01-14 22:22:48.000000000 +0100
***************
*** 22,28 ****
"""This is a judgingclass - a class used to compute the points
a user gets on a specific weekend. Please note that it is possible
that the rules change somewhen and that there is a second judgingclass.
!
The class contains public attributes tdate_min and tdate_max as a
safety-instrument. As soon as you would like to compute points
for a specific tournament which falls outside this limits the script
--- 22,28 ----
"""This is a judgingclass - a class used to compute the points
a user gets on a specific weekend. Please note that it is possible
that the rules change somewhen and that there is a second judgingclass.
!
The class contains public attributes tdate_min and tdate_max as a
safety-instrument. As soon as you would like to compute points
for a specific tournament which falls outside this limits the script
***************
*** 65,71 ****
"""
if not quiet:
! print(' Initializing judging class 2002-12-06 py')
self.quiet = quiet
# ----------------------------------------------------------------
--- 65,71 ----
"""
if not quiet:
! print ' Initializing judging class 2002-12-06 py'
self.quiet = quiet
# ----------------------------------------------------------------
***************
*** 98,104 ****
utils.exit('In judging.prepare_for_database got different lengths of userIDs and values!')
# - Create result
! return [ (values[i], userID[i], cityID[i], paramID[i], tdate[i], betdate[i]) for i in range(len(values)) ]
# ----------------------------------------------------------------
--- 98,108 ----
utils.exit('In judging.prepare_for_database got different lengths of userIDs and values!')
# - Create result
! res = []
! for i in range(len(values)):
! res.append( (values[i],userID[i],cityID[i],paramID[i],tdate[i],betdate[i]) )
!
! return res
# ----------------------------------------------------------------
***************
*** 154,168 ****
to one digit.
"""
! from . import utils
import numpy as np
# - If obs is none at all: return None
if obs is None: return(None)
# - Filter non-None obs
tmp = []
! for i in obs:
! if not i is None: tmp.append( i )
if len(tmp) == 0:
return [0.] * len(data)
--- 158,172 ----
to one digit.
"""
! import utils
import numpy as np
# - If obs is none at all: return None
if obs is None: return(None)
# - Filter non-None obs
tmp = []
! for rec in obs:
! if not rec is None: tmp.append( rec )
if len(tmp) == 0:
return [0.] * len(data)
***************
*** 193,199 ****
# - Loading method dynamical and call it.
if not self.quiet:
! print(' - Using method: %s' % method_to_use)
call = getattr(self,method_to_use)
# Round to one digit after the comma
return np.round( call(obs,data,special), 1 )
--- 197,203 ----
# - Loading method dynamical and call it.
if not self.quiet:
! print ' - Using method: %s' % method_to_use
call = getattr(self,method_to_use)
# Round to one digit after the comma
return np.round( call(obs,data,special), 1 )
***************
*** 216,231 ****
np.ndarray of type float: np.ndarray containing the residuals.
"""
! # - Observations MIN/MAX. If it is only one value MIN is equal to MAX.
obs = np.asarray(obs)
! MIN = np.min(obs)
! MAX = np.max(obs)
# - Compute residuals
resid = np.ndarray(len(data),dtype='float'); resid[:] = -999.
! resid[ np.where(np.logical_and(data >= MIN, data <= MAX)) ] = 0.
! resid[ np.where(data < MIN) ] = np.abs(MIN - data[ np.where(data < MIN) ])
! resid[ np.where(data > MAX) ] = np.abs(MAX - data[ np.where(data > MAX) ])
return resid
--- 220,236 ----
np.ndarray of type float: np.ndarray containing the residuals.
"""
! # - Observations min/max. If it is only one value min is
! # equal to max.
obs = np.asarray(obs)
! min = np.min(obs)
! max = np.max(obs)
# - Compute residuals
resid = np.ndarray(len(data),dtype='float'); resid[:] = -999.
! resid[ np.where(np.logical_and(data >= min, data <= max)) ] = 0.
! resid[ np.where(data < min) ] = np.abs(min - data[ np.where(data < min) ])
! resid[ np.where(data > max) ] = np.abs(max - data[ np.where(data > max) ])
return resid
***************
*** 272,278 ****
"""
if not self.quiet:
! print(' - Called TTm/TTn/TTd point computation method')
data = np.asarray(data)
resid = self.__residuals__(obs,data)
--- 277,283 ----
"""
if not self.quiet:
! print ' - Called TTm/TTn/TTd point computation method'
data = np.asarray(data)
resid = self.__residuals__(obs,data)
***************
*** 307,313 ****
"""
if not self.quiet:
! print(' - Called N point computation method')
data = np.asarray(data)
resid = self.__residuals__(obs,data)
--- 312,318 ----
"""
if not self.quiet:
! print ' - Called N point computation method'
data = np.asarray(data)
resid = self.__residuals__(obs,data)
***************
*** 326,333 ****
# - Special: if observation was 0 or 8 and the
# residual is not equal to 0: subtract one
# more point.
! obs = np.asarray(obs); MIN = np.min(obs); MAX = np.max(obs)
! if MIN == 80. or MAX == 0.:
idx = np.where(resid > 0)
points[idx] = points[idx] - 1.
--- 331,338 ----
# - Special: if observation was 0 or 8 and the
# residual is not equal to 0: subtract one
# more point.
! obs = np.asarray(obs); min = np.min(obs); max = np.max(obs)
! if min == 80. or max == 0.:
idx = np.where(resid > 0)
points[idx] = points[idx] - 1.
***************
*** 336,342 ****
# - Show data (development stuff)
#for i in range(len(data)):
! # print('%2d|%2d: %2d %2d %6.2f' % (MIN/10., MAX/10., data[i]/10., resid[i]/10., points[i]))
return points
--- 341,347 ----
# - Show data (development stuff)
#for i in range(len(data)):
! # print '%2d|%2d: %2d %2d %6.2f' % (min/10., max/10., data[i]/10., resid[i]/10., points[i])
return points
***************
*** 356,362 ****
"""
if not self.quiet:
! print(' - Called Sd point computation method')
data = np.asarray(data)
resid = self.__residuals__(obs,data)
--- 361,367 ----
"""
if not self.quiet:
! print ' - Called Sd point computation method'
data = np.asarray(data)
resid = self.__residuals__(obs,data)
***************
*** 368,384 ****
points = points - resid*0.01
# - If user bet was wrong (resid > 0) and one of the
# observations was 0 (0%) or 10 (1%): subtract additional 1.5 points.
! obs = np.asarray(obs); MIN = np.min(obs); MAX = np.max(obs)
# - Additinoal 1.5 points less between observed 0% and bet 1% or
# higher the other way around.
# - minus 1.5 points. Why + 0.1? I allready subtracted
# 0.1 points because 0/10 makes 10 difference units times
# 0.01 above makes 0.1 points deduction. Therefore I
# have to subtract only 1.5 additional points here.
! idx = np.where( np.logical_and(MAX == 0., data > 0.) )
points[idx] = points[idx] - 1.5 + 0.1
# - The same the other way around
! idx = np.where( np.logical_and(MIN > 0., data == 0.) )
points[idx] = points[idx] - 1.5 + 0.1
# - Cannot be negative
--- 373,389 ----
points = points - resid*0.01
# - If user bet was wrong (resid > 0) and one of the
# observations was 0 (0%) or 10 (1%): subtract additional 1.5 points.
! obs = np.asarray(obs); min = np.min(obs); max = np.max(obs)
# - Additinoal 1.5 points less between observed 0% and bet 1% or
# higher the other way around.
# - minus 1.5 points. Why + 0.1? I allready subtracted
# 0.1 points because 0/10 makes 10 difference units times
# 0.01 above makes 0.1 points deduction. Therefore I
# have to subtract only 1.5 additional points here.
! idx = np.where( np.logical_and(max == 0., data > 0.) )
points[idx] = points[idx] - 1.5 + 0.1
# - The same the other way around
! idx = np.where( np.logical_and(min > 0., data == 0.) )
points[idx] = points[idx] - 1.5 + 0.1
# - Cannot be negative
***************
*** 386,392 ****
# - Show data (development stuff)
#for i in range(len(data)):
! # print '%3d|%3d: %3d %3d %6.2f' % (MIN/10., MAX/10., data[i]/10., resid[i]/10., points[i])
return points
--- 391,397 ----
# - Show data (development stuff)
#for i in range(len(data)):
! # print '%3d|%3d: %3d %3d %6.2f' % (min/10., max/10., data[i]/10., resid[i]/10., points[i])
return points
***************
*** 394,402 ****
# - Compute dd (wind direction)
# ----------------------------------------------------------------
def __points_dd__(self,obs,data,special):
! """
! TODO: crashes if only one dd observed and no wind speed => try/catch fallback
! Rule function to compute points for wind direction parameter.
Args:
obs (): Observations.
--- 399,405 ----
# - Compute dd (wind direction)
# ----------------------------------------------------------------
def __points_dd__(self,obs,data,special):
! """Rule function to compute points for wind direction parameter.
Args:
obs (): Observations.
***************
*** 408,433 ****
"""
if not self.quiet:
! print(' - Called dd point computation method')
data = np.asarray(data)
obs = np.asarray(obs);
try:
! MIN = np.min(obs[np.where( np.logical_and(obs > 0., obs <= 3600. ))])
except:
! MIN = None
try:
! MAX = np.max(obs[np.where( np.logical_and(obs > 0., obs <= 3600. ))])
except:
! MAX = None
# - Change minimum if angle (difference) is bigger than 180 degrees.
! if not MAX == None and not MIN == None:
! if MAX - MIN > 1800.:
! tmp = MAX
! MAX = MIN + 3600.
! MIN = tmp
! # - If min or MAX is none, MIN and MAX are equal
! if not MIN == None and MAX == None: MAX = MIN
! if MIN == None and not MAX == None: MIN = MAX
# - Lowest observed wind speed. Has to be on speical!
# If nothing is observed, assume ffmin == 0 (gives
--- 411,436 ----
"""
if not self.quiet:
! print ' - Called dd point computation method'
data = np.asarray(data)
obs = np.asarray(obs);
try:
! min = np.min(obs[np.where( np.logical_and(obs > 0., obs <= 3600. ))])
except:
! min = None
try:
! max = np.max(obs[np.where( np.logical_and(obs > 0., obs <= 3600. ))])
except:
! max = None
# - Change minimum if angle (difference) is bigger than 180 degrees.
! if not max == None and not min == None:
! if max - min > 1800.:
! tmp = max
! max = min + 3600.
! min = tmp
! # - If min or max is none, min and max are equal
! if not min == None and max == None: max = min
! if min == None and not max == None: min = max
# - Lowest observed wind speed. Has to be on speical!
# If nothing is observed, assume ffmin == 0 (gives
***************
*** 447,459 ****
# - Checking if we have had calm and/or variable conditions
calm = False; variable = False; normal = False
- #falsch#if len( np.where(obs == 0.)[0] ) > 0: calm = True
- #falsch#if len( np.where(obs == 9900.)[0] ) > 0: variable = True
-
- #if at least one wind direction is zero, it's calm
if len( np.where(obs == 0.)[0] ) > 0:
calm = True
- #if at least one direction is variable...
if len( np.where(obs == 9900.)[0] ) > 0:
variable = True
if len( np.where( np.logical_and(obs > 0., obs <= 3600.) )[0] ) > 0:
--- 450,457 ----
***************
*** 473,479 ****
dd_min = np.min( obs[np.where(np.logical_and(obs > 0.,obs<=3600.))] )
dd_max = np.max( obs[np.where(np.logical_and(obs > 0.,obs<=3600.))] )
dd_diff = np.abs( dd_min-dd_max )
!
if len(idx[0]) > 0:
# - Normal penalty
# If minimum wind was less than 6kt: 1.0 points per 10 deg
--- 471,477 ----
dd_min = np.min( obs[np.where(np.logical_and(obs > 0.,obs<=3600.))] )
dd_max = np.max( obs[np.where(np.logical_and(obs > 0.,obs<=3600.))] )
dd_diff = np.abs( dd_min-dd_max )
!
if len(idx[0]) > 0:
# - Normal penalty
# If minimum wind was less than 6kt: 1.0 points per 10 deg
***************
*** 484,490 ****
p_normal[idx] = maxpoints
all_resid[idx] = 0.
else:
! the_obs = np.asarray([MIN, MAX])
residA = self.__residuals__(the_obs-3600.,data[idx])
residB = self.__residuals__(the_obs, data[idx])
residC = self.__residuals__(the_obs+3600.,data[idx])
--- 482,488 ----
p_normal[idx] = maxpoints
all_resid[idx] = 0.
else:
! the_obs = np.asarray([min,max])
residA = self.__residuals__(the_obs-3600.,data[idx])
residB = self.__residuals__(the_obs, data[idx])
residC = self.__residuals__(the_obs+3600.,data[idx])
***************
*** 544,558 ****
#if calm: print ' CALM CONDITION TRUE'
#if variable: print ' VARIABLE CONDITION TRUE'
#print obs
! #print MIN, MAX
! #if MIN == None and MAX == None:
# for i in range(len(data)):
# print '--- | --- bet %3d %6.2f | n: %7.2f s: %7.2f | %7.2f' \
# % (data[i]/10., all_resid[i]/100, p_normal[i], p_special[i], points[i])
#else:
# for i in range(len(data)):
# print '%3d|%3d: bet %3d %6.2f | n: %7.2f s: %7.2f | %7.2f' \
! # % (MIN/10., MAX/10., data[i]/10., all_resid[i]/100, p_normal[i], p_special[i], points[i])
return points
--- 542,556 ----
#if calm: print ' CALM CONDITION TRUE'
#if variable: print ' VARIABLE CONDITION TRUE'
#print obs
! #print min, max
! #if min == None and max == None:
# for i in range(len(data)):
# print '--- | --- bet %3d %6.2f | n: %7.2f s: %7.2f | %7.2f' \
# % (data[i]/10., all_resid[i]/100, p_normal[i], p_special[i], points[i])
#else:
# for i in range(len(data)):
# print '%3d|%3d: bet %3d %6.2f | n: %7.2f s: %7.2f | %7.2f' \
! # % (min/10., max/10., data[i]/10., all_resid[i]/100, p_normal[i], p_special[i], points[i])
return points
***************
*** 572,578 ****
"""
if not self.quiet:
! print(' - Called ff point computation method')
data = np.asarray(data)
resid = self.__residuals__(obs,data)
--- 570,576 ----
"""
if not self.quiet:
! print ' - Called ff point computation method'
data = np.asarray(data)
resid = self.__residuals__(obs,data)
***************
*** 605,619 ****
# - Getting min and max from the obs
data = np.asarray(data)
obs = np.asarray(obs);
! MIN = np.min(obs)
! MAX = np.max(obs)
# - To avoid wrong inputs: knots below 25 (250.)
# are set to 0!
data[np.where( data < 250. )] = 0
if not self.quiet:
! print(' - Called fx point computation method')
data = np.asarray(data)
resid = self.__residuals__(obs,data)
--- 603,617 ----
# - Getting min and max from the obs
data = np.asarray(data)
obs = np.asarray(obs);
! min = np.min(obs)
! max = np.max(obs)
# - To avoid wrong inputs: knots below 25 (250.)
# are set to 0!
data[np.where( data < 250. )] = 0
if not self.quiet:
! print ' - Called fx point computation method'
data = np.asarray(data)
resid = self.__residuals__(obs,data)
***************
*** 627,645 ****
return np.minimum( resid, 150. )*0.025 + np.maximum( resid-150., 0)*0.05
# - Non-special penalty is if fx >= 250 and forecast >= 250 (250=25kt)
! if MAX >= 250.:
idx = np.where( data >= 250. )
points[idx] = points[idx] - normal_penalty( resid[idx] )
# - For these where forecast (data) was 0. but obs was >= 250:
# Special rule. First: -3 points and then normal penalty
# for residuals - 250.
! idx = np.where( np.logical_and( data == 0, MIN >= 250. ) )
points[idx] = maxpoints - 3 - normal_penalty( np.maximum(resid[idx]-250.,0) )
# - For these where forecast (data) was >= 250. but obs was == 0:
# Special rule. First: -3 points and then normal penalty
# for residuals - 250.
! idx = np.where( np.logical_and( data >= 250, MAX == 0. ) )
points[idx] = maxpoints - 3 - normal_penalty( np.maximum(resid[idx]-250.,0) )
# - Now correcting:
--- 625,643 ----
return np.minimum( resid, 150. )*0.025 + np.maximum( resid-150., 0)*0.05
# - Non-special penalty is if fx >= 250 and forecast >= 250 (250=25kt)
! if max >= 250.:
idx = np.where( data >= 250. )
points[idx] = points[idx] - normal_penalty( resid[idx] )
# - For these where forecast (data) was 0. but obs was >= 250:
# Special rule. First: -3 points and then normal penalty
# for residuals - 250.
! idx = np.where( np.logical_and( data == 0, min >= 250. ) )
points[idx] = maxpoints - 3 - normal_penalty( np.maximum(resid[idx]-250.,0) )
# - For these where forecast (data) was >= 250. but obs was == 0:
# Special rule. First: -3 points and then normal penalty
# for residuals - 250.
! idx = np.where( np.logical_and( data >= 250, max == 0. ) )
points[idx] = maxpoints - 3 - normal_penalty( np.maximum(resid[idx]-250.,0) )
# - Now correcting:
***************
*** 649,655 ****
# - Show data (development stuff)
#for i in range(len(data)):
! # print '%5d %5d | %5d %5d %6.2f' % (MIN, MAX, data[i], resid[i], points[i])
return points
# ----------------------------------------------------------------
--- 647,653 ----
# - Show data (development stuff)
#for i in range(len(data)):
! # print '%5d %5d | %5d %5d %6.2f' % (min, max, data[i], resid[i], points[i])
return points
# ----------------------------------------------------------------
***************
*** 683,689 ****
"""
if not self.quiet:
! print(' - Called WvWn point computation method')
data = np.asarray(data)
# Deduction matrix list. Note that 1/2/3 will never be
--- 681,687 ----
"""
if not self.quiet:
! print ' - Called WvWn point computation method'
data = np.asarray(data)
# Deduction matrix list. Note that 1/2/3 will never be
***************
*** 711,717 ****
for o in obs:
for i in range(len(data)):
# maxpoints - observed bet value
! tmp = 10 - point_matrix[int(o/10)][int(data[i]/10)]
# Minimum points: 0!
if tmp < 0:
points[i] = 0.
--- 709,715 ----
for o in obs:
for i in range(len(data)):
# maxpoints - observed bet value
! tmp = 10 - point_matrix[int(o/10)][int(data[i])/10]
# Minimum points: 0!
if tmp < 0:
points[i] = 0.
***************
*** 741,747 ****
"""
if not self.quiet:
! print(' - Called PPP point computation method')
data = np.asarray(data)
resid = self.__residuals__(obs,data)
--- 739,745 ----
"""
if not self.quiet:
! print ' - Called PPP point computation method'
data = np.asarray(data)
resid = self.__residuals__(obs,data)
***************
*** 775,785 ****
# - Getting min and max from the obs
data = np.asarray(data)
obs = np.asarray(obs);
! MIN = np.min(obs)
! MAX = np.max(obs)
if not self.quiet:
! print(' - Called RR point computation method')
data = np.asarray(data)
# - WARNING: compute residuals only to 0mm observation!
# The penalty for observed -3.0 will be added later on.
--- 773,783 ----
# - Getting min and max from the obs
data = np.asarray(data)
obs = np.asarray(obs);
! min = np.min(obs)
! max = np.max(obs)
if not self.quiet:
! print ' - Called RR point computation method'
data = np.asarray(data)
# - WARNING: compute residuals only to 0mm observation!
# The penalty for observed -3.0 will be added later on.
***************
*** 804,817 ****
# -------------------------------------------------------------
# - Now take the penalty vector if max is in that range.
! if MAX <= 0:
penalty = full_penalty
! elif MAX < len(full_penalty):
! penalty = full_penalty[MAX:]
else:
penalty = []
! idx = np.where( data > MAX )[0]
# - For the first len(penalty) deviances
if len(penalty) > 0:
for i in idx:
--- 802,815 ----
# -------------------------------------------------------------
# - Now take the penalty vector if max is in that range.
! if max <= 0:
penalty = full_penalty
! elif max < len(full_penalty):
! penalty = full_penalty[max:]
else:
penalty = []
! idx = np.where( data > max )[0]
# - For the first len(penalty) deviances
if len(penalty) > 0:
for i in idx:
***************
*** 826,834 ****
deduction[idx] = deduction[idx] + np.maximum(0,resid[idx]-len(penalty)) * 0.05
# - Only half points deduction for all forecasted values >= 0.1mm
# if and only if the forecast was bigger than the observed values.
! idx = np.where( np.logical_and( deduction > 0., data > MAX, data > 0 ) )
deduction[idx] = deduction[idx] * 0.5
! # - PROBLEM: if data == 0 and MAX > 0 the user gets
# 1.0 points deduction between 0.0 and 0.1 mm. BUT
# I devided the points by 2. This does not yield
# for the first point 1.0 between 0.0 and 0.1. Therefore
--- 824,832 ----
deduction[idx] = deduction[idx] + np.maximum(0,resid[idx]-len(penalty)) * 0.05
# - Only half points deduction for all forecasted values >= 0.1mm
# if and only if the forecast was bigger than the observed values.
! idx = np.where( np.logical_and( deduction > 0., data > max, data > 0 ) )
deduction[idx] = deduction[idx] * 0.5
! # - PROBLEM: if data == 0 and max > 0 the user gets
# 1.0 points deduction between 0.0 and 0.1 mm. BUT
# I devided the points by 2. This does not yield
# for the first point 1.0 between 0.0 and 0.1. Therefore
***************
*** 838,844 ****
# - Deduction is not equal to 0.
if len(penalty) > 0:
if penalty[0] == 1.:
! idx = np.where( np.logical_and( deduction > 0., data > MAX ) )
deduction[idx] = deduction[idx] + 0.5
# -------------------------------------------------------------
--- 836,842 ----
# - Deduction is not equal to 0.
if len(penalty) > 0:
if penalty[0] == 1.:
! idx = np.where( np.logical_and( deduction > 0., data > max ) )
deduction[idx] = deduction[idx] + 0.5
# -------------------------------------------------------------
***************
*** 848,875 ****
# up to minimum observed value BUT tip was not -3.0mm
# same her with the int() bugfix...
! idx = np.where( data < MIN )[0]
! imax = np.minimum( MIN, len(full_penalty) )
for i in idx:
imin = np.maximum( data[i], 0 )
#possible 0.0 bugfix needs to be tested:
#if imin == imax == 0:
! # slc = 0
#else:
! # slc = range(imin+1,imax+1)
deduction[i] = deduction[i] + np.sum( full_penalty[imin:imax] )
! if MIN > 50.:
! tmp = self.__residuals__( MIN, np.maximum(50, data[idx]) )
deduction[idx] = deduction[idx] + tmp * 0.05
# - Special case: min(obs) was >= 0 but forecast was -3.0
# remove 3 more points.
! if MIN >= 0:
idx = np.where( data < 0)
! deduction[idx] = deduction[idx] + 3
# - Same for case: max(obs) was < 0 (-3.0) but forecast was >=0
! if MAX < 0:
idx = np.where( data >= 0)
deduction[idx] = deduction[idx] + 3
--- 846,873 ----
# up to minimum observed value BUT tip was not -3.0mm
# same her with the int() bugfix...
! idx = np.where( data < min )[0]
! imax = np.minimum( min, len(full_penalty) )
for i in idx:
imin = np.maximum( data[i], 0 )
#possible 0.0 bugfix needs to be tested:
#if imin == imax == 0:
! # slc = 0
#else:
! # slc = range(imin+1,imax+1)
deduction[i] = deduction[i] + np.sum( full_penalty[imin:imax] )
! if min > 50.:
! tmp = self.__residuals__( min, np.maximum(50, data[idx]) )
deduction[idx] = deduction[idx] + tmp * 0.05
# - Special case: min(obs) was >= 0 but forecast was -3.0
# remove 3 more points.
! if min >= 0:
idx = np.where( data < 0)
! deduction[idx] = deduction[idx] + 3
# - Same for case: max(obs) was < 0 (-3.0) but forecast was >=0
! if max < 0:
idx = np.where( data >= 0)
deduction[idx] = deduction[idx] + 3
***************
*** 878,886 ****
points = maxpoints - deduction
# - Show data (development stuff)
! if MIN >=0: print(' WET CONDITIONS')
! if MAX < 0: print(' DRY CONDITIONS')
for i in range(len(data)):
! print('%5d %5d | bet %5d | resid: %5d | %6.2f (ded: %6.2f)' % (MIN, MAX, data[i], resid[i], points[i], deduction[i]))
return points
--- 876,897 ----
points = maxpoints - deduction
# - Show data (development stuff)
! if min >=0: print ' WET CONDITIONS'
! if max < 0: print ' DRY CONDITIONS'
for i in range(len(data)):
! print '%5d %5d | bet %5d | resid: %5d | %6.2f (ded: %6.2f)' % (min,max,data[i], resid[i], points[i], deduction[i])
return points
+
+
+
+
+
+
+
+
+
+
+
+
+
***************
*** 711,717 ****
for o in obs:
for i in range(len(data)):
# maxpoints - observed bet value
! tmp = 10 - point_matrix[int(o/10)][int(data[i]/10)]
# Minimum points: 0!
if tmp < 0:
points[i] = 0.
--- 709,715 ----
for o in obs:
for i in range(len(data)):
# maxpoints - observed bet value
! tmp = 10 - point_matrix[int(o/10)][int(data[i])/10]
# Minimum points: 0!
if tmp < 0:
points[i] = 0.
print() zeugs schon raus gefiltert
*** backend/PythonPackage/pywetterturnier/mitteltip.py 2022-01-06 04:20:12.000000000 +0100
--- backend_old/PythonPackage/pywetterturnier/mitteltip.py 2022-01-14 22:22:48.000000000 +0100
***************
*** 17,23 ****
.. todo:: Could contain a bit more details!
"""
! from . import utils
# - List element to store the two dict dbects
# containing the bets for Petrus
bet = [{},{}]
--- 17,23 ----
.. todo:: Could contain a bit more details!
"""
! import utils
# - List element to store the two dict dbects
# containing the bets for Petrus
bet = [{},{}]
***************
*** 307,339 ****
def random(db,typ,ID,city,tdate,betdata=False):
import numpy as np
! # - Day one, day two
!
for day in range(1,3):
! print(' Compute for day %d (%s)' % (tdate+day, utils.tdate2string( tdate+day )))
param = 'dd'
paramID = db.get_parameter_id(param)
dd = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(dd) == bool: return False
max_dd, min_dd = max(dd), min(dd)
if max_dd == min_dd: bet[day-1][param] = min_dd
elif max_dd - min_dd < 1800:
bet[day-1][param] = np.random.choice( np.arange(min_dd, max_dd+1, 100) )
elif max_dd - min_dd > 1800:
dd_list = []
! for i in range(int(max_dd), int(min_dd+3601), 100):
if i > 3600: i -= 3600
dd_list.append( i )
bet[day-1][param] = np.random.choice( dd_list )
! else: bet[day-1][param] = np.random.choice( np.arange(100, 3601, 100) )
for param in ["N","Sd","ff"]:
paramID = db.get_parameter_id(param)
data = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(data) == bool: return False
min_data, max_data = min(data), max(data)
if min_data == max_data:
bet[day-1][param] = min_data
elif param == "ff" and bet[day-1]["dd"] == 0:
--- 307,351 ----
def random(db,typ,ID,city,tdate,betdata=False):
import numpy as np
! import time as t
! time = lambda : int(t.time())
!
! cityID = city['ID']
! T = (-1)**tdate
! # - Day one, day two
!
for day in range(1,3):
! print ' Compute for day %d (%s)' % (tdate+day, utils.tdate2string( tdate+day ))
param = 'dd'
paramID = db.get_parameter_id(param)
+ seed = (cityID + paramID) * T
dd = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(dd) == bool: return False
max_dd, min_dd = max(dd), min(dd)
if max_dd == min_dd: bet[day-1][param] = min_dd
elif max_dd - min_dd < 1800:
+ np.random.seed( int(time() + seed ) )
bet[day-1][param] = np.random.choice( np.arange(min_dd, max_dd+1, 100) )
elif max_dd - min_dd > 1800:
dd_list = []
! for i in range(int(max_dd), int(min_dd + 3601), 100):
if i > 3600: i -= 3600
dd_list.append( i )
+ np.random.seed( int( time() + seed ) )
bet[day-1][param] = np.random.choice( dd_list )
! else:
! np.random.seed( int( time() + seed ) )
! bet[day-1][param] = np.random.choice( np.arange(100, 3601, 100) )
for param in ["N","Sd","ff"]:
paramID = db.get_parameter_id(param)
+ seed = (cityID + paramID) * T
data = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(data) == bool: return False
min_data, max_data = min(data), max(data)
+ i_min_data = int(min_data/10); i_max_data = int(max_data/10)
if min_data == max_data:
bet[day-1][param] = min_data
elif param == "ff" and bet[day-1]["dd"] == 0:
***************
*** 345,374 ****
if min_data == max_data:
bet[day-1][param] = min_data
elif np.random.random() < p0:
bet[day-1][param] = 0
! else: bet[day-1][param] = np.random.randint( min_data, max_data )
else:
! bet[day-1][param] = np.random.randint( min_data, max_data )
param = "fx"
paramID = db.get_parameter_id(param)
data = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(data) == bool: return False
n0 = np.count_nonzero( data == 0 )
p = n0 / float(len(data))
if np.random.random() < p:
bet[day-1][param] = 0.
else:
min_val = 250
min_data = min(data[data>=min_val])
max_data = max(data)
if min_data == max_data:
bet[day-1][param] = min_data
else:
! bet[day-1][param] = np.random.randint( min_data, max_data )
for param in ["Wv","Wn"]:
paramID = db.get_parameter_id(param)
data = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(data) == bool: return False
W = []
--- 357,395 ----
if min_data == max_data:
bet[day-1][param] = min_data
elif np.random.random() < p0:
+ np.random.seed( int( time() + seed ) )
bet[day-1][param] = 0
! else:
! np.random.seed( int( time() + seed ) )
! bet[day-1][param] = np.random.randint( i_min_data, i_max_data+1 ) * 10
else:
! np.random.seed( int( time() + seed ) )
! bet[day-1][param] = np.random.randint( i_min_data, i_max_data+1 ) * 10
param = "fx"
paramID = db.get_parameter_id(param)
+ seed = (cityID + paramID) * T
data = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(data) == bool: return False
n0 = np.count_nonzero( data == 0 )
p = n0 / float(len(data))
+ np.random.seed( int( time() + seed ) )
if np.random.random() < p:
bet[day-1][param] = 0.
else:
min_val = 250
min_data = min(data[data>=min_val])
max_data = max(data)
+ i_min_data = int(min_data/10); i_max_data = int(max_data/10)
if min_data == max_data:
bet[day-1][param] = min_data
else:
! np.random.seed( int( time() + seed ) )
! bet[day-1][param] = np.random.randint( i_min_data, i_max_data+1 ) * 10
for param in ["Wv","Wn"]:
paramID = db.get_parameter_id(param)
+ seed = (cityID + paramID) * T
data = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(data) == bool: return False
W = []
***************
*** 378,391 ****
if len(W) == 1:
bet[day-1][param] = W[0]
else:
bet[day-1][param] = np.random.choice( W )
param = 'RR'
paramID = db.get_parameter_id(param)
RR = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
! if type(data) == bool: return False
max_RR = max(RR)
! RR_0 = RR[RR>=0]
if len(RR_0) == 0:
min_RR = -30
else:
--- 399,414 ----
if len(W) == 1:
bet[day-1][param] = W[0]
else:
+ np.random.seed( int( time() + seed ) )
bet[day-1][param] = np.random.choice( W )
param = 'RR'
paramID = db.get_parameter_id(param)
+ seed = (cityID + paramID) * T
RR = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
! if type(RR) == bool: return False
max_RR = max(RR)
! RR_0 = RR[RR >= 0]
if len(RR_0) == 0:
min_RR = -30
else:
***************
*** 393,400 ****
--- 416,425 ----
if min_RR == max_RR:
bet[day-1][param] = min_RR
elif bet[day-1]["Wv"] > 40 or bet[day-1]["Wn"] > 40:
+ np.random.seed( int( time() + seed ) )
bet[day-1][param] = np.random.choice( np.arange(min_RR, max_RR+1, 1) )
else:
+ np.random.seed( int( time() + seed ) )
n_3 = np.count_nonzero( RR == -30 )
n0 = np.count_nonzero( RR == 0 )
p_3 = n_3 / float(len(RR))
***************
*** 408,413 ****
--- 433,439 ----
for param in ["PPP","TTm"]:
paramID = db.get_parameter_id(param)
+ seed = (cityID + paramID) * T
data = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(data) == bool: return False
max_data = max(data)
***************
*** 415,424 ****
--- 441,452 ----
if min_data == max_data:
bet[day-1][param] = min_data
else:
+ np.random.seed( int( time() + seed ) )
bet[day-1][param] = np.random.choice( np.arange(min_data, max_data+1, 1) )
for param in ["TTn","TTd"]:
paramID = db.get_parameter_id(param)
+ seed = (cityID + paramID) * T
data = db.get_bet_data(typ,ID,city['ID'],paramID,tdate,day)
if type(data) == bool: return False
max_TTm = bet[day-1]["TTm"]
***************
*** 427,434 ****
--- 455,464 ----
if min_data == max_data:
bet[day-1][param] = min_data
elif max_data > max_TTm:
+ np.random.seed( int( time() + seed ) )
bet[day-1][param] = np.random.choice( np.arange(min_data, max_TTm+1, 1) )
else:
+ np.random.seed( int( time() + seed ) )
bet[day-1][param] = np.random.choice( np.arange(min_data, max_data+1, 1) )
return bet
Chain.py
CheckMergeUsers.py
CleanUpBets.py
ComputeCoefs.py
ComputeFortuna.py
ComputeMeanBets.py
ComputeMoses.py
ComputePersistenzen.py
ComputePetrus.py
ComputePoints.py
ComputeRanksOnly.py
ComputeSleepy.py
ComputeStats.py
ComputeSumPoints.py
ComputeUserStats.py
Observations.py
PlotsStats.py
Rerun.py
TestPoints.py
mtest
Voting.py