retostauffer / wetterturnier-backend

Other
3 stars 2 forks source link

Difference in the backend scripts due to several branches #2

Open mammatus95 opened 2 years ago

mammatus95 commented 2 years ago

Chain.py

*** backend/Chain.py    2022-01-14 22:15:35.000000000 +0100
--- backend_old/Chain.py    2022-01-14 22:19:22.000000000 +0100
***************
*** 43,60 ****

     # - Initializing class and open database connection
     db = database.database(config)

     # - Loading tdate (day since 1970-01-01) for the tournament.
     #   Normaly Friday-Tornament (tdate is then Friday) while
     #   the bet-dates are for Saturday and Sunday.
     is_latest_tournament = False
     if config['input_tdate'] == None:
!       config['input_tdate'] = db.current_tournament()
!       print('  * Using latest tournament date: %d' % config['input_tdate'])
        is_latest_tournament = True
     else:
        #utils.exit('Sorry, need explicit -t/--tdate input for this script')
!       print('  * Using input tdate: %d' % config['input_tdate'])

     # - If input_user was given as string we have to find the
     #   corresponding userID first!
--- 43,62 ----

     # - Initializing class and open database connection
     db = database.database(config)
+    current_tdate = db.current_tournament()
+    today = utils.today_tdate()

     # - Loading tdate (day since 1970-01-01) for the tournament.
     #   Normaly Friday-Tornament (tdate is then Friday) while
     #   the bet-dates are for Saturday and Sunday.
     is_latest_tournament = False
     if config['input_tdate'] == None:
!       config['input_tdate'] = current_tdate
!       print '  * Using latest tournament date: %d' % config['input_tdate']
        is_latest_tournament = True
     else:
        #utils.exit('Sorry, need explicit -t/--tdate input for this script')
!       print '  * Using input tdate: %d' % config['input_tdate']

     # - If input_user was given as string we have to find the
     #   corresponding userID first!
***************
*** 62,91 ****
        config['input_user'] = db.get_user_id( config['input_user'] )
        if not config['input_user']:
           utils.exit('SORRY could not convert your input -u/--user to corresponding userID. Check name.')
! 
! 
     # - Compute the Points for all the dudes first
     import subprocess as sub
     if not config['input_alldates']:
        if is_latest_tournament:
-          #TODO: REMOVE old mean tips before rerunning!
           scripts = ['ComputePetrus.py',
! #                    'ComputeMoses.py',
!                     'ComputeMeanBets.py',
                      'ComputePersistenzen.py',
                      'ComputePoints.py',
                      'ComputeSleepy.py']
        else:
           scripts = ['ComputePetrus.py',
                      'ComputeMeanBets.py',
-                     #'ComputePersistenzen.py',
                      'ComputePoints.py',
                      'ComputeSleepy.py']
     else:
        scripts = ['ComputePetrus.py',
                   'ComputeMeanBets.py',
-  #                'ComputeMoses.py',
-  #                'ComputePersistenzen',
                   'ComputePoints.py',
                   'ComputeSleepy.py']

--- 64,93 ----
        config['input_user'] = db.get_user_id( config['input_user'] )
        if not config['input_user']:
           utils.exit('SORRY could not convert your input -u/--user to corresponding userID. Check name.')
!    
     # - Compute the Points for all the dudes first
     import subprocess as sub
     if not config['input_alldates']:
        if is_latest_tournament:
           scripts = ['ComputePetrus.py',
!                     'ComputeMoses.py',
                      'ComputePersistenzen.py',
+                     'ComputeMeanBets.py',
                      'ComputePoints.py',
                      'ComputeSleepy.py']
+          if today == current_tdate:
+             print "Today is a tournament day!"  
        else:
           scripts = ['ComputePetrus.py',
+ #                    'ComputePersistenzen.py',
                      'ComputeMeanBets.py',
                      'ComputePoints.py',
                      'ComputeSleepy.py']
     else:
        scripts = ['ComputePetrus.py',
+    #              'ComputeMoses.py',
+    #              'ComputePersistenzen',
                   'ComputeMeanBets.py',
                   'ComputePoints.py',
                   'ComputeSleepy.py']

***************
*** 104,108 ****
        p1 = sub.Popen(cmd,stderr=sub.PIPE)
        err = p1.communicate()
        if not p1.returncode == 0:
!          for line in err: print('%s\n' % line)
           utils.exit('ERROR WHILE RUNNING %s AS SUBPROCESS FOR DATE %d' % (script,config['input_tdate']))
--- 106,110 ----
        p1 = sub.Popen(cmd,stderr=sub.PIPE)
        err = p1.communicate()
        if not p1.returncode == 0:
!          for line in err: print '%s\n' % line
           utils.exit('ERROR WHILE RUNNING %s AS SUBPROCESS FOR DATE %d' % (script,config['input_tdate']))

CheckMergeUsers.py

*** backend/CheckMergeUsers.py  2022-01-06 04:17:44.000000000 +0100
--- backend_old/CheckMergeUsers.py  2022-01-14 22:19:22.000000000 +0100
***************
*** 19,26 ****

     import numpy as np
     # - Wetterturnier specific modules
!    from pywetterturnier import utils
!    from pywetterturnier import database

     # - Evaluating input arguments
     inputs = utils.inputcheck('CheckMergeUsers')
--- 19,25 ----

     import numpy as np
     # - Wetterturnier specific modules
!    from pywetterturnier import utils, database

     # - Evaluating input arguments
     inputs = utils.inputcheck('CheckMergeUsers')
***************
*** 34,45 ****
     # Usage notification
     # ----------------------------------------------------------------
     if not config['input_user']:
!       print("[!] Stop. Input -u/--user has to be set")
!       print("    Example: --user reto,rto,tro would")
!       print("    check whether we can merge these three")
!       print("    users in the database. The FIRST one ")
!       print("    is the leading user (the others will be")
!       print("    removed and set to the leading user).")
        sys.exit(9)
     else:
        users = []
--- 33,44 ----
     # Usage notification
     # ----------------------------------------------------------------
     if not config['input_user']:
!       print "[!] Stop. Input -u/--user has to be set"
!       print "    Example: --user reto,rto,tro would"
!       print "    check whether we can merge these three"
!       print "    users in the database. The FIRST one "
!       print "    is the leading user (the others will be"
!       print "    removed and set to the leading user)."
        sys.exit(9)
     else:
        users = []
***************
*** 48,54 ****
           rec = rec.strip()
           if not rec in users: users.append(rec)
        if len(rec) < 2:
!          print("Input -u/--usres: at least two required!"); sys.exit(9)

     # ----------------------------------------------------------------
     # Check if users exist
--- 47,53 ----
           rec = rec.strip()
           if not rec in users: users.append(rec)
        if len(rec) < 2:
!          print "Input -u/--usres: at least two required!"; sys.exit(9)

     # ----------------------------------------------------------------
     # Check if users exist
***************
*** 57,80 ****
     for u in range(0,len(users)):
        userids[u] = db.get_user_id( users[u] )
        if not userids[u]:
!          print("[!] Stop. User \"%s\" could not be found." % users[u])
           sys.exit(9)
        if u == 0:
!          print("   MASTER user:   %-20s   [uid %5d]" % (users[u],userids[u]))
        else:
!          print("   Slave user:    %-20s   [uid %5d]" % (users[u],userids[u]))

     # ----------------------------------------------------------------
!    # Bit inefficient, however, allows to show the data in a talbe form
     # ----------------------------------------------------------------
     sql = "SELECT count(*) AS count FROM wp_wetterturnier_betstat WHERE " + \
           "userID = %d AND tdate = %d"

     # Show header
!    print(" %10s %6s " % ("date","tdate"), end=' ')
     for u in range(0,len(users)):
!       print(" %10s " % users[u], end=' ')
!    print("") # line break

     # Final variable. If set to False we would not allow to merge.
     # If 'True' merging would be allowed.
--- 56,79 ----
     for u in range(0,len(users)):
        userids[u] = db.get_user_id( users[u] )
        if not userids[u]:
!          print "[!] Stop. User \"%s\" could not be found." % users[u]
           sys.exit(9)
        if u == 0:
!          print "   MASTER user:   %-20s   [uid %5d]" % (users[u],userids[u])
        else:
!          print "   Slave user:    %-20s   [uid %5d]" % (users[u],userids[u])

     # ----------------------------------------------------------------
!    # Bit inefficient, however, allows to show the data in a table form
     # ----------------------------------------------------------------
     sql = "SELECT count(*) AS count FROM wp_wetterturnier_betstat WHERE " + \
           "userID = %d AND tdate = %d"

     # Show header
!    print " %10s %6s " % ("date","tdate"),
     for u in range(0,len(users)):
!       print " %10s " % users[u],
!    print "" # line break

     # Final variable. If set to False we would not allow to merge.
     # If 'True' merging would be allowed.
***************
*** 91,108 ****
        if np.max(counts) == 0: continue

        # Show frontend
!       print(" %10s %6d " % (utils.tdate2string(tdate),tdate), end=' ')
        for u in range(0,len(users)):
!          print(" %10d " % counts[u], end=' ')
        if len(np.where(np.array(counts) > 0)[0]) == 1:
!          print("    merge ok")
        else:
           merging_allowed = False
!          print("    [ERROR] MERGING NOT ALLOWED (OVERLAP)")

     if not merging_allowed:
!       print("\n\n  !!!!   MERGING NOT ALLOWED !!!!!\n\n")
        db.close()
        sys.exit(9)

--- 90,107 ----
        if np.max(counts) == 0: continue

        # Show frontend
!       print " %10s %6d " % (utils.tdate2string(tdate),tdate),
        for u in range(0,len(users)):
!          print " %10d " % counts[u],
        if len(np.where(np.array(counts) > 0)[0]) == 1:
!          print "    merge ok"
        else:
           merging_allowed = False
!          print "    [ERROR] MERGING NOT ALLOWED (OVERLAP)"

     if not merging_allowed:
!       print "\n\n  !!!!   MERGING NOT ALLOWED !!!!!\n\n"
        db.close()
        sys.exit(9)

***************
*** 110,122 ****
     # ----------------------------------------------------------------
     # Else merge user
     # ----------------------------------------------------------------
!    print("\n\n  ++++ merging is allowed ++++\n\n")
!    print(" * Merge users now")

     cur = db.cursor()
     for u in range(1,len(users)):

!       print("   Merge %s [%d] >>> %s [%d]" % (users[u],userids[u],users[0],userids[0]))
        # Update wetterturnier tables
        bets = "UPDATE wp_wetterturnier_bets SET userID = %d WHERE userID = %d" % \
               (userids[0],userids[1])
--- 109,121 ----
     # ----------------------------------------------------------------
     # Else merge user
     # ----------------------------------------------------------------
!    print "\n\n  ++++ merging is allowed ++++\n\n"
!    print " * Merge users now"

     cur = db.cursor()
     for u in range(1,len(users)):

!       print "   Merge %s [%d] >>> %s [%d]" % (users[u],userids[u],users[0],userids[0])
        # Update wetterturnier tables
        bets = "UPDATE wp_wetterturnier_bets SET userID = %d WHERE userID = %d" % \
               (userids[0],userids[1])
***************
*** 133,154 ****
        cur.execute( usr )
        cur.execute( usrmeta )

!    db.commit()
!       
     db.close()
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
--- 132,136 ----
        cur.execute( usr )
        cur.execute( usrmeta )

!    db.commit()   
     db.close()

CleanUpBets.py

*** backend/CleanUpBets.py  2022-01-06 04:17:44.000000000 +0100
--- backend_old/CleanUpBets.py  2022-01-14 22:19:23.000000000 +0100
***************
*** 13,19 ****
     # - If input_user was given as string we have to find the
     #   corresponding userID first!
     if not config['input_user'] == None:
!       print('[!] NOTE: got input -u/--user. Will be ignored in CleanBets.')
        config['input_user'] = None

--- 13,19 ----
     # - If input_user was given as string we have to find the
     #   corresponding userID first!
     if not config['input_user'] == None:
!       print '[!] NOTE: got input -u/--user. Will be ignored in CleanBets.'
        config['input_user'] = None

***************
*** 28,59 ****
     else:
        tdates      = [config['input_tdate']]

!    print('  * Current tournament is %s' % utils.tdate2string( tdates[0] ))
     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     for city in cities:
!       print("Now cleaning up bets in %s" % city['name'])
        # ----------------------------------------------------------------
        # - If alldates, take all tdates from database
        # ----------------------------------------------------------------
        if config['input_alldates']:
           tdates = db.all_tournament_dates( city['ID'] )
        for tdate in tdates:
!          print(utils.tdate2string( tdate ))
           check = utils.datelock( config, tdate )
           if check:
!             print("    Date is 'locked' (datelock). Dont execute.")
              continue
           missing = db.find_missing_bets( city['ID'], tdate )
           if missing == False:
!             print("OK"); continue
           else:
              for userID in missing:
                 db.delete_bet( userID, city['ID'], tdate )
--- 28,59 ----
     else:
        tdates      = [config['input_tdate']]

!    print '  * Current tournament is %s' % utils.tdate2string( tdates[0] )
     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     for city in cities:
!       print "Now cleaning up bets in %s" % city['name']
        # ----------------------------------------------------------------
        # - If alldates, take all tdates from database
        # ----------------------------------------------------------------
        if config['input_alldates']:
           tdates = db.all_tournament_dates( city['ID'] )
        for tdate in tdates:
!          print utils.tdate2string( tdate )
           check = utils.datelock( config, tdate )
           if check:
!             print "    Date is 'locked' (datelock). Dont execute."
              continue
           missing = db.find_missing_bets( city['ID'], tdate )
           if missing == False:
!             print "OK"; continue
           else:
              for userID in missing:
                 db.delete_bet( userID, city['ID'], tdate )
***************
*** 61,64 ****
     db.commit()
     db.close()

!    print("Cleaning finished - GOOD NIGHT!")
--- 61,64 ----
     db.commit()
     db.close()

!    print "Cleaning finished - GOOD NIGHT!"

ComputeCoefs.py

*** backend/ComputeCoefs.py 2022-01-06 04:17:44.000000000 +0100
--- backend_old/ComputeCoefs.py 2022-01-14 22:19:23.000000000 +0100
***************
*** 0 ****
--- 1,39 ----
+ from pywetterturnier import database, utils
+ import numpy
+ import moses as m
+ 
+ def coefs(cities):
+    #calling the fortran program for each city
+    for city in cities:
+       m.moses.processmoses( city['name'][0].lower() + "pw" )
+ 
+ 
+ if __name__ == "__main__":
+    # - Evaluating input arguments
+    inputs = utils.inputcheck('ComputeCoefs')
+    # - Read configuration file
+    config = utils.readconfig('config.conf',inputs)
+ 
+    # - Initializing class and open database connection
+    db        = database.database(config)
+    # - Loading tdate (day since 1970-01-01) for the tournament.
+    #   Normaly Friday-Tornament (tdate is then Friday) while
+    #   the bet-dates are for Saturday and Sunday if there was
+    #   no input tournament date -t/--tdate.
+    if config['input_tdate'] == None:
+       tdates     = [db.current_tournament()]
+    else:
+       tdates     = [config['input_tdate']]
+ 
+    # - Loading all different cities (active cities)
+    cities     = db.get_cities()
+    print cities
+    # - If input city set, then drop all other cities.
+    if not config['input_city'] == None:
+       tmp = []
+       for elem in cities:
+    if elem['name'] == config['input_city']: tmp.append( elem )
+       cities = tmp
+ 
+    #call function
+    coefs(cities)

ComputeFortuna.py

ComputeMeanBets.py

*** backend/ComputeMeanBets.py  2022-01-06 04:17:44.000000000 +0100
--- backend_old/ComputeMeanBets.py  2022-01-14 22:19:23.000000000 +0100
***************
*** 35,41 ****
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print('  * Current tournament is %s' % utils.tdate2string( tdates[0] ))
     else:
        tdates     = [config['input_tdate']]

--- 35,41 ----
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print '  * Current tournament is %s' % utils.tdate2string( tdates[0] )
     else:
        tdates     = [config['input_tdate']]

***************
*** 44,51 ****
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     # - Loading all active users from the database
--- 44,51 ----
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     # - Loading all active users from the database
***************
*** 62,70 ****
     # - Check if input_user is an active group.
     if not config['input_user'] == None:
        if not config['input_user'] in active_groups:
!          print('    Some help for you: currently active groups:')
           for grp in active_groups:
!             print('    - %s' % grp)
           utils.exit('Sorry, but %s is not a name of an active group. Stop.' % config['input_user'])
        else:
           active_groups = [config['input_user']]
--- 62,70 ----
     # - Check if input_user is an active group.
     if not config['input_user'] == None:
        if not config['input_user'] in active_groups:
!          print '    Some help for you: currently active groups:'
           for grp in active_groups:
!             print '    - %s' % grp
           utils.exit('Sorry, but %s is not a name of an active group. Stop.' % config['input_user'])
        else:
           active_groups = [config['input_user']]
***************
*** 75,81 ****
        today = utils.today_tdate()
        hour = datetime.utcnow().hour
        minute = datetime.utcnow().minute
!       if i == "MOS-Random" and not (hour == 15 and minute in [0,1] and today == tdates[0]):
           continue
           #pass
        active_groups.append( i )
--- 75,81 ----
        today = utils.today_tdate()
        hour = datetime.utcnow().hour
        minute = datetime.utcnow().minute
!       if i == "MOS-Random" and not (hour == 15 and minute in list(range(15)) and today == tdates[0]):
           continue
           #pass
        active_groups.append( i )
***************
*** 98,105 ****
        # - Getting users for the groups
        for city in cities:

!          print('\n  * Compute the %s (groupID %d) for city %s (ID: %d)' % \
!                    (username,groupID,city['name'], city['ID'])) 

           # ----------------------------------------------------------------
           # - If aldates, take all tdates from database
--- 98,105 ----
        # - Getting users for the groups
        for city in cities:

!          print '\n  * Compute the %s (groupID %d) for city %s (ID: %d)' % \
!                    (username,groupID,city['name'], city['ID']) 

           # ----------------------------------------------------------------
           # - If aldates, take all tdates from database
***************
*** 112,131 ****
           # ----------------------------------------------------------------
           for tdate in tdates:

              # Check number of participants for this city, weekend, and group
              participants = db.get_participants_in_group(groupID,city['ID'],tdate)
!             print(("    Found user ID's: {:s}".format(", ".join(
!                             ["{:d}".format(x) for x in participants]))))

              if len(participants) < 2:
!                print("[!] Less than 2 participants for this group/city/tdate.")
!                print("    Skip computation of mean bets and delete old group bet if exists.")
                 group_userID = db.get_user_id( username )
!                print("Group's userID: %s" % group_userID)
                 db.delete_bet( group_userID, city['ID'], tdate )
                 continue

!             print('    Current tdate is: %d' % tdate)

              # ----------------------------------------------------------------
              # - Check if we are allowed to perform the computation of the
--- 112,136 ----
           # ----------------------------------------------------------------
           for tdate in tdates:

+             check = utils.datelock(config,tdate)
+             if not config['input_force'] and check:
+                print '    Date is \'locked\' (datelock). Dont execute, skip.'
+                continue
+ 
              # Check number of participants for this city, weekend, and group
              participants = db.get_participants_in_group(groupID,city['ID'],tdate)
!             print("    Found user ID's: {:s}".format(", ".join(
!                             ["{:d}".format(x) for x in participants])))

              if len(participants) < 2:
!                print "[!] Less than 2 participants for this group/city/tdate."
!                print "    Skip computation of mean bets and delete old group bet if exists."
                 group_userID = db.get_user_id( username )
!                print "Group's userID: %s" % group_userID
                 db.delete_bet( group_userID, city['ID'], tdate )
                 continue

!             print '    Current tdate is: %d' % tdate

              # ----------------------------------------------------------------
              # - Check if we are allowed to perform the computation of the
***************
*** 133,139 ****
              # ----------------------------------------------------------------
              check = utils.datelock(config,tdate)
              if check:
!                print('    Date is \'locked\' (datelock). Dont execute, skip.')
                 continue

              # ----------------------------------------------------------------
--- 138,144 ----
              # ----------------------------------------------------------------
              check = utils.datelock(config,tdate)
              if check:
!                print '    Date is \'locked\' (datelock). Dont execute, skip.'
                 continue

              # ----------------------------------------------------------------
***************
*** 143,150 ****
              #   never compute the corresponding points). Skip. 
              # ----------------------------------------------------------------
              if tdate < 12027:
!                print('[!] I dont know the rules to compute points before 2002-12-06')
!                print('    Therefore it makes no sense to compute MeanBets. Skip.') 
                 continue

              # -------------------------------------------------------------
--- 148,155 ----
              #   never compute the corresponding points). Skip. 
              # ----------------------------------------------------------------
              if tdate < 12027:
!                print '[!] I dont know the rules to compute points before 2002-12-06'
!                print '    Therefore it makes no sense to compute MeanBets. Skip.' 
                 continue

              # -------------------------------------------------------------
***************
*** 168,187 ****
              #   continue.
              # -------------------------------------------------------------
              if not bet:
!                print('[!] At least one parameter returned no data. Skip!!')
                 continue

              # -------------------------------------------------------------
              # - Inserting into database now
              # -------------------------------------------------------------
!             print('    Inserting data into database now')
              for day in range(1,3):
!                for k in list(bet[day-1].keys()):
                    paramID = db.get_parameter_id(k)
                    db.upsert_bet_data(userID,city['ID'],paramID,tdate,day,bet[day-1][k])

     db.commit()
     db.close()
- 
- print(today, hour, minute)
--- 173,190 ----
              #   continue.
              # -------------------------------------------------------------
              if not bet:
!                print '[!] At least one parameter returned no data. Skip!!'
                 continue

              # -------------------------------------------------------------
              # - Inserting into database now
              # -------------------------------------------------------------
!             print '    Inserting data into database now'
              for day in range(1,3):
!                for k in bet[day-1].keys():
                    paramID = db.get_parameter_id(k)
                    db.upsert_bet_data(userID,city['ID'],paramID,tdate,day,bet[day-1][k])

     db.commit()
     db.close()

ComputeMoses.py

*** backend/ComputeMoses.py 2022-01-06 04:17:44.000000000 +0100
--- backend_old/ComputeMoses.py 2022-01-14 22:19:23.000000000 +0100
***************
*** 23,30 ****
     from pywetterturnier import utils, database, mitteltip
     from datetime import datetime as dt
     import numpy as np
!    from PrintMoses import print_moses
!    
     # - Evaluating input arguments
     inputs = utils.inputcheck('ComputeMoses')
     # - Read configuration file
--- 23,29 ----
     from pywetterturnier import utils, database, mitteltip
     from datetime import datetime as dt
     import numpy as np
! 
     # - Evaluating input arguments
     inputs = utils.inputcheck('ComputeMoses')
     # - Read configuration file
***************
*** 32,58 ****

     # - Initializing class and open database connection
     db        = database.database(config)
- 
-    # - Loading all different cities (active cities)
-    cities     = db.get_cities()
- 
     # - Loading tdate (day since 1970-01-01) for the tournament.
     #   Normaly Friday-Tornament (tdate is then Friday) while
     #   the bet-dates are for Saturday and Sunday if there was
     #   no input tournament date -t/--tdate.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
-       today      = utils.today_tdate()
-       #if db.get_moses_coefs( 1, tdates[0] ) == False:
-       #if today == tdates[0] + 4 and db.get_moses_coefs( 1, tdates[0] ) == False:
-          #it's gotta be Tuesday then. And we only look if coefs for Berlin exists cause we're hackers
-       import numpy
-       import moses as m
-       #execute moses.f90 programm for each cities to keep coefs up to date once a week
-       print_moses( db, config, cities, tdates ) 
-       for i in cities:
-          m.moses.processmoses( i['hash'] )
- 
     else:
        tdates     = [config['input_tdate']]

--- 31,42 ----
***************
*** 61,68 ****
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     # - If moses directory does not exist:
--- 45,52 ----
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     # - If moses directory does not exist:
***************
*** 71,77 ****
                 "the necessary coefficient-files for Moses! Stop!")

     # - Reading parameter list
!    params = db.get_parameter_names(active=True, sort=True)

     # ----------------------------------------------------------------
     # - Prepare the Moses
--- 55,61 ----
                 "the necessary coefficient-files for Moses! Stop!")

     # - Reading parameter list
!    params = db.get_parameter_names(False)

     # ----------------------------------------------------------------
     # - Prepare the Moses
***************
*** 82,88 ****

     # ----------------------------------------------------------------
     # - A small helper function to find the correct coefficient
!    #   file. Klaus sends them once a week, normally on 
     #   Tuesday. The name of the file contains a date 
     #   but this is not the tournament date and normally
     #   the name of the files has 'a delay'.
--- 66,72 ----

     # ----------------------------------------------------------------
     # - A small helper function to find the correct coefficient
!    #   file. Klaus Knuepffer sends them once a week, normally on 
     #   Tuesday. The name of the file contains a date 
     #   but this is not the tournament date and normally
     #   the name of the files has 'a delay'.
***************
*** 102,108 ****
        moses_files = glob( "{0:s}/moses*.{1:1s}pw".format(config['data_moses'], city['name'][0].lower()) )
        # - empty?
        if len( moses_files ) == 0:
!          print('    %s\n' % 'Cannot find moses coefficients, skip')
           return( False )

        origin = dt.date(1970,1,1)
--- 86,92 ----
        moses_files = glob( "{0:s}/moses*.{1:1s}pw".format(config['data_moses'], city['name'][0].lower()) )
        # - empty?
        if len( moses_files ) == 0:
!          print '    %s\n' % 'Cannot find moses coefficients, skip'
           return( False )

        origin = dt.date(1970,1,1)
***************
*** 113,140 ****
        for file in moses_files:
           mtch = re.match( ".*moses([0-9]{6})\.\wpw$", file )
           if not mtch is None:
!             file_dates.append( dt.datetime.strptime( mtch.group(1), "%y%m%d").date() )
        # Newest moses file
        newest      = max( file_dates )
        newest_file = "{0:s}/moses{1:s}.{2:1s}pw".format(
                      config['data_moses'], newest.strftime("%y%m%d"), city['name'][0].lower() )
!       print("    Newest matching moses file: {0:s} ({1:s})".format(
!                     newest.strftime("%Y-%m-%d"), newest_file ))

        # If the file is too old: return FALSE. As the file should be computed
        # between each tournament it should never be older than 7 days, I take 5 here
        # just in case.
!       if offset == False: return newest_file
        age = (dt.date.today() - newest).days

        # Drop a warning and return False if too old.
        if age > offset:
!           print("[!] Problems with Moses: coefficient file too old ({0:d} days)".format(age))
!           print("    Return 'False', Moses wont be computed!")
            return False

!       # Else return file name of the newest file, tdate
!       return newest_file

     # ----------------------------------------------------------------
--- 97,125 ----
        for file in moses_files:
           mtch = re.match( ".*moses([0-9]{6})\.\wpw$", file )
           if not mtch is None:
!            file_dates.append( dt.datetime.strptime( mtch.group(1), "%y%m%d").date() )
! 
        # Newest moses file
        newest      = max( file_dates )
        newest_file = "{0:s}/moses{1:s}.{2:1s}pw".format(
                      config['data_moses'], newest.strftime("%y%m%d"), city['name'][0].lower() )
!       print "    Newest matching moses file: {0:s} ({1:s})".format(
!                     newest.strftime("%Y-%m-%d"), newest_file )

        # If the file is too old: return FALSE. As the file should be computed
        # between each tournament it should never be older than 7 days, I take 5 here
        # just in case.
!       if offset == False: return [newest_file, newest]
        age = (dt.date.today() - newest).days

        # Drop a warning and return False if too old.
        if age > offset:
!           print "[!] Problems with Moses: coefficient file too old ({0:d} days)".format(age)
!           print "    Return 'False', Moses wont be computed!"
            return False

!       # Else return file name of the newest file
!       return [newest_file, newest]

     # ----------------------------------------------------------------
***************
*** 144,150 ****
     # ----------------------------------------------------------------
     petrus_userID = db.get_user_id( "Petrus" )
     if not petrus_userID:
!       print("[!] Cannot find \"Petrus\" (User) needed for Moses. Stop script here.")
        sys.exit(0)

     # ----------------------------------------------------------------
--- 129,135 ----
     # ----------------------------------------------------------------
     petrus_userID = db.get_user_id( "Petrus" )
     if not petrus_userID:
!       print "[!] Cannot find \"Petrus\" (User) needed for Moses. Stop script here."
        sys.exit(0)

     # ----------------------------------------------------------------
***************
*** 153,178 ****
     for city in cities:
        if config['input_alldates']:
           tdates = db.all_tournament_dates( city['ID'] )
!          print('ALL DATES')

        # -------------------------------------------------------------
        #  - Looping over tdates
        # -------------------------------------------------------------
        for tdate in tdates:
           bet = [{},{}]
!          print('\n  * Compute the %s for city %s (ID: %d)' % (username, city['name'], city['ID'])) 
!          
!          # - Searching suitable coefficient file
           #   ... WARNING 200 offset disabled, but we do have a problem
           #       at the moment to get the newest coefficients, so with offset false
           #       we are using old files.
!          moses_file = get_moses_file(tdate, city, offset = False )
!          if moses_file: moses_tdate = utils.string2tdate( moses_file[18:-4], moses = True )
! 
           if not moses_file: continue

!          print('  * Found newest moses file %s' % moses_file)
!          mfid = open(moses_file, encoding="iso-8859-1", errors='ignore')
           moses_data = iter(mfid.read().split('\n'))
           moses = {}
           for param in params: moses[param] = {}
--- 138,170 ----
     for city in cities:
        if config['input_alldates']:
           tdates = db.all_tournament_dates( city['ID'] )
!          print 'ALL DATES'

        # -------------------------------------------------------------
        #  - Looping over tdates
        # -------------------------------------------------------------
        for tdate in tdates:
+ 
+          check = utils.datelock(config,tdate)
+          if not config['input_force'] and check:
+             print '    Date is \'locked\' (datelock). Dont execute, skip.'
+             continue
+ 
           bet = [{},{}]
!          print '\n  * Compute the %s for city %s (ID: %d)' % (username,city['name'], city['ID']) 
!       
!          # - Searching sutable coefficient file
           #   ... WARNING 200 offset disabled, but we do have a problem
           #       at the moment to get the newest coefficients, so with offset false
           #       we are using old files.
!          moses_file_info = get_moses_file(tdate,city, offset = False )
!          moses_file = moses_file_info[0]
!          moses_date = str( moses_file_info[1] )
!          #print moses_date
           if not moses_file: continue

!          print '  * Found newest moses file %s' % moses_file
!          mfid = open(moses_file,'r')
           moses_data = iter(mfid.read().split('\n'))
           moses = {}
           for param in params: moses[param] = {}
***************
*** 181,238 ****
                 param=line.strip()
              elif len(line.split()) == 2:
                 user = line.split()[1]
-                print(user)
                 if user == "Persistenz": user = "Donnerstag"
!                moses[param][user] = line.split()[0]
              else: continue
           db.upsert_moses_coefs(city['ID'], moses_tdate, moses)
!          moses = db.get_moses_coefs(city['ID'], tdate)
!          print(moses)
           # -------------------------------------------------------------
           # - Looping over all parameters, search for Moses coefficients
           #   and try to find the bets of the users.
           for param in params:
              paramID = db.get_parameter_id( param )  
              for day in range(2):
                 bet[day][param] = np.array([])
                 users           = moses[param]
!                for user in users:
!                   if user == "Persistenz": user = "Donnerstag" 
!                   userID  = db.get_user_id( user )
!                   groupID = db.get_user_id( "GRP_%s" % user )
! 
!                   if not userID: userID = groupID 
! 
!                   if not userID:
!                      print('    - Problems getting userID for user %s' % (user))
!                      utils.exit('Reto, should not happen. What doing now?')
!                   
!                      #   and parameter 'paramID' for day 'day'.
!                      #   If there are no data, continue!
                    value = db.get_bet_data('user',userID,city['ID'],paramID,tdate,day+1)
!                   coef  = moses[param][user]
                    # - If value is False the player did not submit his/her bet!

                    if value == False: continue
                    else:
                       bet[day][param] = np.append( bet[day][param], np.repeat( value, int(float(coef)*100000) ) )
                 #   Use Petrus fallback.
!                if len(bet[day][param]) == 0:
!                   bet[day][param] = db.get_bet_data('user',petrus_userID,city['ID'],paramID,tdate,day+1)
           bet = mitteltip.mitteltip(db,'moses',False,city,tdate,bet)
!          
           # - If bet is False, continue
           if bet == False: continue

           # -------------------------------------------------------------
!          # - Inserting into database now
!          # -------------------------------------------------------------
!          print('    Inserting data into database now')
           for day in range(1,3):
!             for k in params:
                 paramID = db.get_parameter_id(k)
                 db.upsert_bet_data(moses_userID,city['ID'],paramID,tdate,day,bet[day-1][k])

     db.commit()
     db.close()
- 
--- 173,225 ----
                 param=line.strip()
              elif len(line.split()) == 2:
                 user = line.split()[1]
                 if user == "Persistenz": user = "Donnerstag"
!                userID = db.get_user_id( user )
!                if not userID: print "NO userID!"; continue
!                moses[param][userID] = line.split()[0]
              else: continue
+ 
+          moses_tdate = utils.string2tdate( moses_date )
           db.upsert_moses_coefs(city['ID'], moses_tdate, moses)
!          moses = db.get_moses_coefs(city['ID'], moses_tdate)
! 
           # -------------------------------------------------------------
           # - Looping over all parameters, search for Moses coefficients
           #   and try to find the bets of the users.
           for param in params:
+             #print param
              paramID = db.get_parameter_id( param )  
              for day in range(2):
+                #print "day %d" % int(day+1)
                 bet[day][param] = np.array([])
                 users           = moses[param]
!                for userID in users:
                    value = db.get_bet_data('user',userID,city['ID'],paramID,tdate,day+1)
!                   coef  = moses[param][userID]
                    # - If value is False the player did not submit his/her bet!

                    if value == False: continue
                    else:
+                      #TODO dont work wiht append, create array first, then fill it!
                       bet[day][param] = np.append( bet[day][param], np.repeat( value, int(float(coef)*100000) ) )
                 #   Use Petrus fallback.
!                bet_count = len(bet[day][param])
!                if bet_count < 100000:
!                   #TODO same here...
!                   bet[day][param] = np.append( bet[day][param], np.repeat( db.get_bet_data('user',petrus_userID,city['ID'],paramID,tdate,day+1), (100000 - bet_count ) ) )
           bet = mitteltip.mitteltip(db,'moses',False,city,tdate,bet)
!          #print bet
           # - If bet is False, continue
           if bet == False: continue

           # -------------------------------------------------------------
!    # - Inserting into database now
!    # -------------------------------------------------------------
!          print '    Inserting data into database now'
           for day in range(1,3):
!             for k in bet[day-1].keys():
                 paramID = db.get_parameter_id(k)
                 db.upsert_bet_data(moses_userID,city['ID'],paramID,tdate,day,bet[day-1][k])

     db.commit()
     db.close()

ComputePersistenzen.py

*** backend/ComputePersistenzen.py  2022-01-06 04:17:44.000000000 +0100
--- backend_old/ComputePersistenzen.py  2022-01-14 22:19:23.000000000 +0100
***************
*** 1,5 ****
  # -------------------------------------------------------------------
! # - NAME:        ComputePersistenz.py
  # - AUTHOR:      Reto Stauffer
  # - DATE:        2015-07-29
  # - LICENSE: GPL-3, Reto Stauffer, copyright 2014
--- 1,5 ----
  # -------------------------------------------------------------------
! # - NAME:        ComputePersistenzen.py
  # - AUTHOR:      Reto Stauffer
  # - DATE:        2015-07-29
  # - LICENSE: GPL-3, Reto Stauffer, copyright 2014
***************
*** 37,62 ****
     #   no input tournament date -t/--tdate.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
     else:
        tdates     = [config['input_tdate']]
!       print(tdates)
     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     for i,j in zip( ["Donnerstag","Freitag"], [1,0] ):
!       print(i, j)
        # ----------------------------------------------------------------
        # - Prepare the Persistenz
        # ----------------------------------------------------------------
        username = i
!       db.create_user( username )
        userID = db.get_user_id( username )

        # -------------------------------------------------------------
--- 37,67 ----
     #   no input tournament date -t/--tdate.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
+ 
     else:
        tdates     = [config['input_tdate']]
!    print "Current tournament is %s" % utils.tdate2string( tdates[0] )
! 
     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

+    # - Reading parameter list
+    params = db.get_parameter_names(False)
+    

     for i,j in zip( ["Donnerstag","Freitag"], [1,0] ):
!       print i, j
        # ----------------------------------------------------------------
        # - Prepare the Persistenz
        # ----------------------------------------------------------------
        username = i
!       #db.create_user( username )
        userID = db.get_user_id( username )

        # -------------------------------------------------------------
***************
*** 64,84 ****
        # -------------------------------------------------------------
        def remove_bool_from_list( x ):
           res = []
!          for i in x:
!             if not isinstance(i, bool):
                 res.append( elem )
           return res

        # ----------------------------------------------------------------
        # - Loopig over all tournament dates
        # ----------------------------------------------------------------
-       from datetime import datetime as dt
        for tdate in tdates:

!          # - Using obervations of the tournament day for our Persistenz player
!          tdate_str = dt.fromtimestamp( tdate-j * 86400 ).strftime('%a, %Y-%m-%d')

!          print("    Searching for Observations:     %s (%d)" % (tdate_str, tdate-j))

           # ----------------------------------------------------------------
           # - Check if we are allowed to perform the computation of the
--- 69,92 ----
        # -------------------------------------------------------------
        def remove_bool_from_list( x ):
           res = []
!          for elem in x:
!             if not isinstance(elem,bool):
                 res.append( elem )
           return res

        # ----------------------------------------------------------------
        # - Loopig over all tournament dates
        # ----------------------------------------------------------------
        for tdate in tdates:

!          check = utils.datelock(config,tdate)
!          if not config['input_force'] and check:
!             print '    Date is \'locked\' (datelock). Dont execute, skip.'
!             continue

!          # - Using obervations of the tournament day for our Persistenz player
!          tdate_str = utils.tdate2string( tdate - j )
!          print "    Searching for Observations:     %s (%d)" % (tdate_str,tdate-j)

           # ----------------------------------------------------------------
           # - Check if we are allowed to perform the computation of the
***************
*** 86,116 ****
           # ----------------------------------------------------------------
           check = utils.datelock(config,tdate-j)
           if check:
!             print('    Date is \'locked\' (datelock). Dont execute, skip.')
              continue

           # ----------------------------------------------------------------
           # - Compute mitteltip mean of all stations of each city... 
           # ----------------------------------------------------------------
           for city in cities:
!             print('\n  * Compute the %s for city %s (ID: %d)' % (username,city['name'], city['ID']))

!             # - bit hacky: go 1 day back in mitteltip function to get obs
              #   instead of user bets like in Petrus. typ='persistenz' for db
              #   idea: we could also take thursday's obs for saturday and
              #   fridays tip for sunday, or even saturday's for sunday...
              bet = mitteltip.mitteltip(db,'persistenz',False,city,tdate-j)
!             print(bet) 
              # - If bet is False, continue
!             if bet == False: continue

              # - Save into database. Note: we have loaded the persistence
              #   data from the tournament (e.g. Friday)
              #   but have to store for two days (saturday, sunday). Therefore
              #   there is the day-loop here.
              for day in range(1,3):
!                print("    Insert Persistenz bets into database for day %d" % day)
!                for k in list(bet[day-1].keys()):
                    paramID = db.get_parameter_id(k)
                    db.upsert_bet_data(userID,city['ID'],paramID,tdate,day,bet[day-1][k])

--- 94,124 ----
           # ----------------------------------------------------------------
           check = utils.datelock(config,tdate-j)
           if check:
!             print '    Date is \'locked\' (datelock). Dont execute, skip.'
              continue

           # ----------------------------------------------------------------
           # - Compute mitteltip mean of all stations of each city... 
           # ----------------------------------------------------------------
           for city in cities:
!             print '\n  * Compute the %s for city %s (ID: %d)' % (username,city['name'], city['ID'])

!             # - bit hacky: go j days back in mitteltip function and get obs
              #   instead of user bets like in Petrus. typ='persistenz' for db
              #   idea: we could also take thursday's obs for saturday and
              #   fridays tip for sunday, or even saturday's for sunday...
              bet = mitteltip.mitteltip(db,'persistenz',False,city,tdate-j)
!             
              # - If bet is False, continue
!             if bet == False: print "NO BETDATA"; continue

              # - Save into database. Note: we have loaded the persistence
              #   data from the tournament (e.g. Friday)
              #   but have to store for two days (saturday, sunday). Therefore
              #   there is the day-loop here.
              for day in range(1,3):
!                print "    Insert %s bets into database for day %d" % (i, day)
!                for k in bet[day-1].keys():
                    paramID = db.get_parameter_id(k)
                    db.upsert_bet_data(userID,city['ID'],paramID,tdate,day,bet[day-1][k])

ComputePetrus.py

*** backend/ComputePetrus.py    2022-01-06 04:17:44.000000000 +0100
--- backend_old/ComputePetrus.py    2022-01-14 22:19:23.000000000 +0100
***************
*** 30,36 ****
     # - If input_user was given as string we have to find the
     #   corresponding userID first!
     if not config['input_user'] == None:
!       print('[!] NOTE: got input -u/--user. Will be ignored in ComputePetrus.')
        config['input_user'] = None

--- 30,36 ----
     # - If input_user was given as string we have to find the
     #   corresponding userID first!
     if not config['input_user'] == None:
!       print '[!] NOTE: got input -u/--user. Will be ignored in ComputePetrus.'
        config['input_user'] = None

***************
*** 45,58 ****
     else:
        tdates      = [config['input_tdate']]

!    print('  * Current tournament is %s' % utils.tdate2string( tdates[0] ))
     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

--- 45,58 ----
     else:
        tdates      = [config['input_tdate']]

!    print '  * Current tournament is %s' % utils.tdate2string( tdates[0] )
     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

***************
*** 68,74 ****
     # ----------------------------------------------------------------
     for city in cities:

!       print('\n  * Compute the %s for city %s (ID: %d)' % (username,city['name'], city['ID'])) 

        if config['input_alldates']:
           tdates = db.all_tournament_dates( city['ID'] )
--- 68,74 ----
     # ----------------------------------------------------------------
     for city in cities:

!       print '\n  * Compute the %s for city %s (ID: %d)' % (username,city['name'], city['ID']) 

        if config['input_alldates']:
           tdates = db.all_tournament_dates( city['ID'] )
***************
*** 83,91 ****
           #   mean bets on this date
           # ----------------------------------------------------------------
           check = utils.datelock(config,tdate)
!          if check:
!             print('    Date is \'locked\' (datelock). Dont execute, skip.')
!             continue

     # ----------------------------------------------------------------
     # - I do not have the judgingclass before the rule changes in
--- 83,91 ----
           #   mean bets on this date
           # ----------------------------------------------------------------
           check = utils.datelock(config,tdate)
!    if check:
!       print '    Date is \'locked\' (datelock). Dont execute, skip.'
!       continue

     # ----------------------------------------------------------------
     # - I do not have the judgingclass before the rule changes in
***************
*** 93,102 ****
     #   to compute MeanBets for that time period (becuase we can
     #   never compute the corresponding points). Skip. 
     # ----------------------------------------------------------------
!          if tdate < 12027:
!             print('[!] I dont know the rules to compute points before 2002-12-06')
!             print('    Therefore it makes no sense to compute MeanBets. Skip.')
!             continue

           # - Returns list object containing two dicts 
           #   where all the bets are in.
--- 93,102 ----
     #   to compute MeanBets for that time period (becuase we can
     #   never compute the corresponding points). Skip. 
     # ----------------------------------------------------------------
!    if tdate < 12027:
!       print '[!] I dont know the rules to compute points before 2002-12-06'
!       print '    Therefore it makes no sense to compute MeanBets. Skip.'
!       continue

           # - Returns list object containing two dicts 
           #   where all the bets are in.
***************
*** 108,116 ****
           # -------------------------------------------------------------
           # - Inserting into database now
           # -------------------------------------------------------------
!          print('    Inserting data into database now')
           for day in range(1,3):
!             for k in list(bet[day-1].keys()):
                 paramID = db.get_parameter_id(k)
                 db.upsert_bet_data(userID,city['ID'],paramID,tdate,day,bet[day-1][k])

--- 108,116 ----
           # -------------------------------------------------------------
           # - Inserting into database now
           # -------------------------------------------------------------
!          print '    Inserting data into database now'
           for day in range(1,3):
!             for k in bet[day-1].keys():
                 paramID = db.get_parameter_id(k)
                 db.upsert_bet_data(userID,city['ID'],paramID,tdate,day,bet[day-1][k])

ComputePoints.py

*** backend/ComputePoints.py    2022-01-15 10:50:15.000000000 +0100
--- backend_old/ComputePoints.py    2022-01-14 22:19:23.000000000 +0100
***************
*** 15,21 ****
  import sys, os
  sys.path.append('PyModules')

- 
  # - Start as main script (not as module)
  if __name__ == '__main__':

--- 15,20 ----
***************
*** 35,41 ****
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print('  * Current tournament is %s' % utils.tdate2string( tdates[0] ))
     else:
        tdates     = [config['input_tdate']]

--- 34,40 ----
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print '  * Current tournament is %s' % utils.tdate2string( tdates[0] )
     else:
        tdates     = [config['input_tdate']]

***************
*** 58,65 ****
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     # ----------------------------------------------------------------
--- 57,64 ----
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     # ----------------------------------------------------------------
***************
*** 78,94 ****
        # -------------------------------------------------------------
        for tdate in tdates:

-          print('  * Current tournament is %s' % utils.tdate2string( tdate ))
- 
           # ----------------------------------------------------------------
           # - Check if we are allowed to perform the computation of the
           #   mean bets on this date
           # ----------------------------------------------------------------
           check = utils.datelock(config,tdate)
           if not config['input_force'] and check:
!             print('    Date is \'locked\' (datelock). Dont execute, skip.')
              continue

           # ----------------------------------------------------------
           # - Which judgingclass do we have to take?
           #   It is possible that the scoring system changed.
--- 77,93 ----
        # -------------------------------------------------------------
        for tdate in tdates:

           # ----------------------------------------------------------------
           # - Check if we are allowed to perform the computation of the
           #   mean bets on this date
           # ----------------------------------------------------------------
           check = utils.datelock(config,tdate)
           if not config['input_force'] and check:
!             print '    Date is \'locked\' (datelock). Dont execute, skip.'
              continue

+          print '  * Current tournament is %s' % utils.tdate2string( tdate )
+ 
           # ----------------------------------------------------------
           # - Which judgingclass do we have to take?
           #   It is possible that the scoring system changed.
***************
*** 96,102 ****
           #   Take the latest judgingclass changed in 2002-12-06
           if tdate < 12027:
              if config['input_ignore']:
!                print('[!] Judginglcass not defined - but started in ignore mode. Skip.')
                 continue
              else:
                 utils.exit('I dont know which judgingclass I should use for this date. Stop.')
--- 95,101 ----
           #   Take the latest judgingclass changed in 2002-12-06
           if tdate < 12027:
              if config['input_ignore']:
!                print '[!] Judginglcass not defined - but started in ignore mode. Skip.'
                 continue
              else:
                 utils.exit('I dont know which judgingclass I should use for this date. Stop.')
***************
*** 109,115 ****
              from importlib import import_module
              judging = import_module(modname)
           except Exception as e:
!             print(e)
              utils.exit("Problems loading the judgingclass %s" % modname)

           jug = judging.judging()
--- 108,114 ----
              from importlib import import_module
              judging = import_module(modname)
           except Exception as e:
!             print e
              utils.exit("Problems loading the judgingclass %s" % modname)

           jug = judging.judging()
***************
*** 119,126 ****
           # ----------------------------------------------------------
           for day in range(1,3):

!             print('\n  * Compute points for city %s (ID: %d)' % (city['name'], city['ID']))
!             print('    Bets for: %s' % utils.tdate2string( tdate + day ))

              # -------------------------------------------------------
              # - Compute points
--- 118,125 ----
           # ----------------------------------------------------------
           for day in range(1,3):

!             print '\n  * Compute points for city %s (ID: %d)' % (city['name'], city['ID'])
!             print '    Bets for: %s' % utils.tdate2string( tdate + day )

              # -------------------------------------------------------
              # - Compute points
***************
*** 131,142 ****
                    if not param == config['input_param']: continue

                 paramID = db.get_parameter_id( param )
!                print('    Compute points for %s (paramID: %d)' % (param, paramID))

                 # - Gettig observations
                 obs = db.get_obs_data(city['ID'],paramID,tdate,day)
                 if not obs:
!                   print('    Observations not available. Skip at that time.')
                    continue

                 # - Loading city observations
--- 130,141 ----
                    if not param == config['input_param']: continue

                 paramID = db.get_parameter_id( param )
!                print '    Compute points for %s (paramID: %d)' % (param, paramID)

                 # - Gettig observations
                 obs = db.get_obs_data(city['ID'],paramID,tdate,day)
                 if not obs:
!                   print '    Observations not available. Skip at that time.'
                    continue

                 # - Loading city observations
***************
*** 145,155 ****
                 tmp = db.get_cityall_bet_data(city['ID'],paramID,tdate,day,nullonly=nullonly)
                 # Gotno data?
                 if not tmp[0] or not tmp[1]:
!                   print("[!] Got no data to compute the points. Skip"); continue
                 db_userID, db_cityID, db_paramID, db_tdate, db_betdate, values = tmp
                 # - No data: skip 
                 if not values:
!                   print('    Got no data for this parameter. Skip.')
                    continue

                 # - If the parameter to judge is "dd" we need additional
--- 144,154 ----
                 tmp = db.get_cityall_bet_data(city['ID'],paramID,tdate,day,nullonly=nullonly)
                 # Gotno data?
                 if not tmp[0] or not tmp[1]:
!                   print "[!] Got no data to compute the points. Skip"; continue
                 db_userID, db_cityID, db_paramID, db_tdate, db_betdate, values = tmp
                 # - No data: skip 
                 if not values:
!                   print '    Got no data for this parameter. Skip.'
                    continue

                 # - If the parameter to judge is "dd" we need additional
***************
*** 162,168 ****

                 # - Now compute points
                 points = jug.get_points(obs,param,values,special,tdate)
!                print(points) 
                 jug.points_to_database( db, db_userID, db_cityID, db_paramID, db_tdate, \
                                         db_betdate, points )

--- 161,167 ----

                 # - Now compute points
                 points = jug.get_points(obs,param,values,special,tdate)
!    
                 jug.points_to_database( db, db_userID, db_cityID, db_paramID, db_tdate, \
                                         db_betdate, points )

ComputeRanksOnly.py

*** backend/ComputeRanksOnly.py 2022-01-06 04:17:45.000000000 +0100
--- backend_old/ComputeRanksOnly.py 2022-01-14 22:19:23.000000000 +0100
***************
*** 15,30 ****
  import sys, os
  sys.path.append('PyModules')

- 
  # - Start as main script (not as module)
  if __name__ == '__main__':

     import numpy as np
     # - Wetterturnier specific modules
     from pywetterturnier import utils, database
! 
     # - Evaluating input arguments
!    inputs = utils.inputcheck('ComputeRanksOnly')
     # - Read configuration file
     config = utils.readconfig('config.conf',inputs)

--- 15,29 ----
  import sys, os
  sys.path.append('PyModules')

  # - Start as main script (not as module)
  if __name__ == '__main__':

     import numpy as np
     # - Wetterturnier specific modules
     from pywetterturnier import utils, database
!    
     # - Evaluating input arguments
!    inputs = utils.inputcheck('ComputePoints')
     # - Read configuration file
     config = utils.readconfig('config.conf',inputs)

***************
*** 35,41 ****
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print('  * Current tournament is %s' % utils.tdate2string( tdates[0] ))
     else:
        tdates     = [config['input_tdate']]

--- 34,40 ----
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print '  * Current tournament is %s' % utils.tdate2string( tdates[0] )
     else:
        tdates     = [config['input_tdate']]

***************
*** 46,52 ****
        config['input_user'] = db.get_user_id( config['input_user'] )
        if not config['input_user']:
           utils.exit('SORRY could not convert your input -u/--user to corresponding userID. Check name.')
! 
     # - Loading all parameters
     params = db.get_parameter_names(False)

--- 45,51 ----
        config['input_user'] = db.get_user_id( config['input_user'] )
        if not config['input_user']:
           utils.exit('SORRY could not convert your input -u/--user to corresponding userID. Check name.')
!    
     # - Loading all parameters
     params = db.get_parameter_names(False)

***************
*** 59,66 ****
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     # ----------------------------------------------------------------
--- 58,65 ----
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     # ----------------------------------------------------------------
***************
*** 74,79 ****
--- 73,79 ----
           tdates = db.all_tournament_dates( city['ID'] )

        for tdate in tdates:
+ 
           cur = db.cursor()

           sql = "SELECT userID, points FROM wp_wetterturnier_betstat " + \
***************
*** 83,91 ****
           tmp = cur.fetchall()
           data   = []
           points = []
!          for i in tmp:
!             data.append( [int( i[0] ),float( i[1] ),None] )
!             points.append( float( i[1] ) )

           # Take unique points and reverse-sort them
           points = np.unique(points)
--- 83,91 ----
           tmp = cur.fetchall()
           data   = []
           points = []
!          for rec in tmp:
!             data.append( [int(rec[0]),float(rec[1]),None] )
!             points.append( float(rec[1]) )

           # Take unique points and reverse-sort them
           points = np.unique(points)

ComputeSleepy.py

*** backend/ComputeSleepy.py    2022-01-06 04:17:45.000000000 +0100
--- backend_old/ComputeSleepy.py    2022-01-14 22:19:23.000000000 +0100
***************
*** 48,54 ****
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print('  * Current tournament is %s' % utils.tdate2string( tdates[0] ))
     else:
        tdates     = [config['input_tdate']]

--- 48,54 ----
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print '  * Current tournament is %s' % utils.tdate2string( tdates[0] )
     else:
        tdates     = [config['input_tdate']]

***************
*** 57,64 ****
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     # ----------------------------------------------------------------
--- 57,64 ----
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     # ----------------------------------------------------------------
***************
*** 67,73 ****
     username = 'Sleepy'
     db.create_user( username )
     userID = db.get_user_id( username )
!    print('    The userID of the sleepy is %d' % userID)

     #exclude Sleepy, Referenztipps and Mitteltipps (groups)
     ignore = [userID] 
--- 67,73 ----
     username = 'Sleepy'
     db.create_user( username )
     userID = db.get_user_id( username )
!    print '    The userID of the sleepy is %d' % userID

     #exclude Sleepy, Referenztipps and Mitteltipps (groups)
     ignore = [userID] 
***************
*** 85,91 ****
     # ----------------------------------------------------------------
     for city in cities:

!       print('\n  * Compute the %s for city %s (ID: %d)' % (username,city['name'], city['ID'])) 

        # ----------------------------------------------------------------
        # - If aldates, take all tdates from database
--- 85,91 ----
     # ----------------------------------------------------------------
     for city in cities:

!       print '\n  * Compute the %s for city %s (ID: %d)' % (username,city['name'], city['ID']) 

        # ----------------------------------------------------------------
        # - If aldates, take all tdates from database
***************
*** 98,111 ****
        # ----------------------------------------------------------------
        for tdate in tdates:

           # - Returns list object containing two dicts 
           #   where all the bets are in.
           points = db.get_sleepy_points(city['ID'],tdate,ignore)
           if points == False: continue
!  
           # - Insert Sleepy points
!          print('    Inserting Sleepy points for %d' % tdate)
!          print("    UPSERT: user %d, city %d, tdate %d, points %f " % (userID,city['ID'],tdate,points))

           db.upsert_sleepy_points(userID,city['ID'],tdate,points)

--- 98,116 ----
        # ----------------------------------------------------------------
        for tdate in tdates:

+          check = utils.datelock(config,tdate)
+          if not config['input_force'] and check:
+             print '    Date is \'locked\' (datelock). Dont execute, skip.'
+             continue
+ 
           # - Returns list object containing two dicts 
           #   where all the bets are in.
           points = db.get_sleepy_points(city['ID'],tdate,ignore)
           if points == False: continue
!          print "    Sleepy = " + str(points)
           # - Insert Sleepy points
!          print '    Inserting Sleepy points for %d' % tdate
!          print "    UPSERT: user %d, city %d, tdate %d, points %f " % (userID,city['ID'],tdate,points)

           db.upsert_sleepy_points(userID,city['ID'],tdate,points)

ComputeStats.py

*** backend/ComputeStats.py 2022-01-06 04:17:45.000000000 +0100
--- backend_old/ComputeStats.py 2022-01-14 22:19:23.000000000 +0100
***************
*** 8,17 ****

     # - Evaluating input arguments
     inputs = utils.inputcheck('ComputeStats')
-    print(inputs)
     # - Read configuration file
     config = utils.readconfig('config.conf',inputs)
-    print(config)
     # - Initializing class and open database connection
     db        = database.database(config)

--- 8,15 ----
***************
*** 21,48 ****
     #   no input tournament date -t/--tdate.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print('  * Current tournament is %s' % utils.tdate2string( tdates[0] ))
     else:
        tdates     = [config['input_tdate']]

!    #-p option for testing minimum participations, exponent formula
     if config['input_param'] == None:
!       typ = "sd_logfit"
     else:
!       typ = config['input_param']

     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     userIDs = db.get_all_users()

!    measures=["points_adj","points","part","mean","median","Qlow","Qupp","max","min","sd"]

     # check whether current tournament is finished to keep open tournaments out of the userstats
     today              = utils.today_tdate()
--- 19,51 ----
     #   no input tournament date -t/--tdate.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print '  * Current tournament is %s' % utils.tdate2string( tdates[0] )
     else:
        tdates     = [config['input_tdate']]

!    #verbose switch for debugging
!    if config["input_verbose"]:
!       verbose = True
!    else: verbose = False
! 
!    #-p option for testing sigmoid function, setting midpoint where y=0.5
     if config['input_param'] == None:
!       par = [100, 25] #pmid, pout
     else:
!       par = config['input_param'].split(",")

     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     userIDs = db.get_all_users()

!    measures=["sd_ind","points_adj","points","part","mean","median","Qlow","Qupp","max","min","sd"]

     # check whether current tournament is finished to keep open tournaments out of the userstats
     today              = utils.today_tdate()
***************
*** 59,96 ****
     for city in cities:
        if config['input_alldates']:
           tdates = db.all_tournament_dates( city['ID'] )
!          print('ALL DATES')
        for tdate in tdates:
           for day in range(3):
!             stats = db.get_stats( city['ID'], measures[-8:]+["sd_upp"], 0, tdate, day )
              #if all stats are 0 we assume that no tournament took place on tdate
!             if list(stats.values()) == [0] * len(stats):
                 continue
              else:
                 db.upsert_stats( city['ID'], stats, 0, tdate, day)

        #Compute citystats which can be used for plotting box whiskers etc
        #TODO: we should already calculate the fit coefficients m,n / A,B,C later used for plotting here
!       stats = db.get_stats( city['ID'], measures[-7:] + ["mean_part","max_part","min_part","tdates"], last_tdate = last_tdate )
        db.upsert_stats( city['ID'], stats )

     if config['input_tdate'] == None:

        #calculate userstats, first import aliases.json as dict
-       from json import load
        with open("aliases.json") as aliases:
           aliases = load( aliases )
!       print(aliases)
!       for userID in userIDs:
!          user = db.get_username_by_id(userID)
!          for city in cities:
!             for day in range(3):
!                stats = db.get_stats( city['ID'], measures, userID, 0, day, last_tdate, aliases=aliases, typ=typ, pout=25, pmin=50 )
!                db.upsert_stats( city['ID'], stats, userID, 0, day)
! 
!       sql = "SELECT wu.user_login, us.points_adj %s FROM %swetterturnier_userstats us JOIN wp_users wu ON userID = wu.ID WHERE cityID=%d "
!       sql += "AND part >= 25 AND user_login NOT LIKE 'Sleepy' ORDER BY points_adj DESC"
!       cols = ",".join( measures[:4] )

        if config['input_filename'] == None:
           filename = "eternal_list"
--- 62,110 ----
     for city in cities:
        if config['input_alldates']:
           tdates = db.all_tournament_dates( city['ID'] )
!          print 'ALL DATES'
        for tdate in tdates:
           for day in range(3):
!             stats = db.compute_stats( city['ID'], measures[-8:]+["sd_upp"], 0, tdate, day )
              #if all stats are 0 we assume that no tournament took place on tdate
!             if stats.values() == [0] * len(stats):
                 continue
              else:
                 db.upsert_stats( city['ID'], stats, 0, tdate, day)

        #Compute citystats which can be used for plotting box whiskers etc
        #TODO: we should already calculate the fit coefficients m,n / A,B,C later used for plotting here
!       stats = db.compute_stats( city['ID'], measures[-7:] + ["mean_part","max_part","min_part","tdates"], last_tdate = last_tdate )
        db.upsert_stats( city['ID'], stats )

     if config['input_tdate'] == None:

+       #append pseudo-city for all cities ranking
+       cities.append( {"name":"all_cities", "hash":"ALL", "ID":0} )
+       cities.append( {"name":"all_cities_weighted","hash":"ALW","ID":6} )
+ 
        #calculate userstats, first import aliases.json as dict
        with open("aliases.json") as aliases:
+          from json import load
           aliases = load( aliases )
!          for userID in userIDs:
!             user = db.get_username_by_id(userID)
!             for city in cities:
!                for day in range(3):
!                   stats = db.compute_stats( city['ID'], measures+["ranks_weekend"], userID, 0, day, last_tdate, aliases=aliases, pmid=int(par[0]), pout=int(par[1]) )
!                   db.upsert_stats( city['ID'], stats, userID, 0, day )
!       
!       sql = """
!          SELECT wu.user_login, %s
!          FROM %swetterturnier_userstats us
!          JOIN wp_users wu ON userID = wu.ID
!          WHERE cityID=%d AND part >= 25
!          ORDER BY points_adj DESC
!       """
! 
!       cols = ",".join(("ROUND(points_adj, 1) AS points_adj",
!                        "ROUND(points_med, 1) AS points_med",
!                        "ROUND(sd_ind, 1) AS sd_ind", "part") )

        if config['input_filename'] == None:
           filename = "eternal_list"
***************
*** 100,113 ****
        #generating ranking table output, write to .xls file
        with pd.ExcelWriter( "plots/%s.xls" % filename ) as writer:
           for city in cities:
              table = pd.read_sql_query( sql % ( cols, db.prefix, city['ID'] ), db )
              table.to_excel( writer, sheet_name = city["hash"] )
-             print(table)

        #now we call a plotting routine which draws some nice statistical plots
        import PlotStats
        tdate = max(tdates) - 7
!       PlotStats.plot(db, cities, tdate)

     db.commit()
     db.close()
--- 114,129 ----
        #generating ranking table output, write to .xls file
        with pd.ExcelWriter( "plots/%s.xls" % filename ) as writer:
           for city in cities:
+             print city["hash"]
              table = pd.read_sql_query( sql % ( cols, db.prefix, city['ID'] ), db )
+             print table
              table.to_excel( writer, sheet_name = city["hash"] )

        #now we call a plotting routine which draws some nice statistical plots
        import PlotStats
        tdate = max(tdates) - 7
!       print "Calling plot routine now..."
!       PlotStats.plot(db, cities[:-2], tdate, verbose=False)

     db.commit()
     db.close()

ComputeSumPoints.py

*** backend/ComputeSumPoints.py 2022-01-15 10:39:54.000000000 +0100
--- backend_old/ComputeSumPoints.py 2022-01-14 22:19:23.000000000 +0100
***************
*** 25,31 ****
     import sys, os
     import numpy as np
     from pywetterturnier import utils
!    print('\n  * Compute sum points to fill betstat table')

     # ----------------------------------------------------------------
     # - Now going over the cities and compute the points. 
--- 25,31 ----
     import sys, os
     import numpy as np
     from pywetterturnier import utils
!    print '\n  * Compute sum points to fill betstat table'

     # ----------------------------------------------------------------
     # - Now going over the cities and compute the points. 
***************
*** 42,69 ****
        # - Looping trough dates
        # -------------------------------------------------------------
        for tdate in tdates:
           # ----------------------------------------------------------------
           # - Check if we are allowed to perform the computation of the
           #   mean bets on this date
           # ----------------------------------------------------------------
           check = utils.datelock(config,tdate)
           if check:
!             print('    Date is \'locked\' (datelock). Dont execute, skip.')
              continue

!          # ----------------------------------------------------------
!          # - Which judgingclass do we have to take?
!          #   It is possible that the scoring system changed.
!          # ----------------------------------------------------------
!          #   Take the latest judgingclass changed in 2002-12-06
!          if tdate < 12027:
!             if config['input_ignore']:
!                print('[!] Judginglcass not defined - but started in ignore mode. Skip.')
!                continue
!             else:
!                utils.exit('I dont know which judgingclass I should use for this date. Stop.')
! 
!          print('    For %s tournament is %s' % (city['name'], utils.tdate2string( tdate )))

           # - If config['input_user'] is an integer value this
           #   is a userID. Compute the sum points for this user
--- 42,58 ----
        # - Looping trough dates
        # -------------------------------------------------------------
        for tdate in tdates:
+ 
           # ----------------------------------------------------------------
           # - Check if we are allowed to perform the computation of the
           #   mean bets on this date
           # ----------------------------------------------------------------
           check = utils.datelock(config,tdate)
           if check:
!             print '    Date is \'locked\' (datelock). Dont execute, skip.'
              continue

!          print '    For %s tournament is %s' % (city['name'], utils.tdate2string( tdate ))

           # - If config['input_user'] is an integer value this
           #   is a userID. Compute the sum points for this user
***************
*** 98,104 ****
                      'AND p.cityID = d2.cityID ' + \
                      ''

!          print('    - Reading data from database')
           cur = db.cursor()
           cur.execute( sql_full )
           desc = cur.description
--- 87,93 ----
                      'AND p.cityID = d2.cityID ' + \
                      ''

!          print '    - Reading data from database'
           cur = db.cursor()
           cur.execute( sql_full )
           desc = cur.description
***************
*** 106,115 ****

           # Now compute 
           if len(data) == 0:
!             print('    - Sorry, got no data to compute sum points')
           else:
              # Else: we have data, update database
!             print('    - Upserting database (%d lines)' % len(data))

              # Require the index of the "points" variable
              points_idx = None
--- 95,104 ----

           # Now compute 
           if len(data) == 0:
!             print '    - Sorry, got no data to compute sum points'
           else:
              # Else: we have data, update database
!             print '    - Upserting database (%d lines)' % len(data)

              # Require the index of the "points" variable
              points_idx = None
***************
*** 132,143 ****
              # Compute rank
              points = []
              for pi in range(0,len(data)): points.append(data[pi][points_idx])
!             print(points)
!             try:
!                 points = np.sort(points)[::-1]
!             except:
!                 print("ERROR: error while computing ranks")
!                 sys.exit(0)

              rank = []
              data = list(data)
--- 121,127 ----
              # Compute rank
              points = []
              for pi in range(0,len(data)): points.append(data[pi][points_idx])
!             points = np.sort(points)[::-1]

              rank = []
              data = list(data)
***************
*** 194,208 ****
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     # - Calling the function now
     CSP(db,config,cities,tdates)

     db.commit()
-    db.close()
- 
- 
- 
--- 178,188 ----
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     # - Calling the function now
     CSP(db,config,cities,tdates)

     db.commit()

ComputeUserStats.py

*** backend/ComputeUserStats.py 2022-01-06 04:17:45.000000000 +0100
--- backend_old/ComputeUserStats.py 2022-01-14 22:19:23.000000000 +0100
***************
*** 9,28 ****
     # - Evaluating input arguments
     inputs = utils.inputcheck('ComputeUserStats')

- 
     # - Read configuration file
     config = utils.readconfig('config.conf',inputs)
     # - Initializing class and open database connection
     db        = database.database(config)

- 
     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     #userIDs = db.get_all_users()
--- 9,26 ----
     # - Evaluating input arguments
     inputs = utils.inputcheck('ComputeUserStats')

     # - Read configuration file
     config = utils.readconfig('config.conf',inputs)
     # - Initializing class and open database connection
     db        = database.database(config)

     # - Loading all different cities (active cities)
     cities     = db.get_cities()
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     #userIDs = db.get_all_users()
***************
*** 41,64 ****
     #-s => compare multiple users
     for i in users:
        userIDs.append( db.get_user_id(i) )
-    #print users; userIDs

!    measures=["points_adj","points_adj1","points_adj2","part"]
     #measures=["part","points","mean","median","sd","max","min"]

-    #-t option to quickly set asymptote ymax
-    if config['input_tdate'] == None:
-       ymax = 185
-    else:
-       ymax = config['input_tdate']
- 
     #-p option for testing minimum participations and exponent formula
     if config['input_param'] == None:
!       par = [25,50]
     else:
        par = config['input_param'].split(",")

!    mids = {1:2010, 2:2010, 3:2011, 4:2012, 5:2013, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0}

     #verbose switch for debugging
     if config["input_verbose"]:
--- 39,56 ----
     #-s => compare multiple users
     for i in users:
        userIDs.append( db.get_user_id(i) )

!    measures=["points_adj","sd_ind1","sd_ind2","points_adj1","points_adj2","part"]
!    #measures = ["points_adj","part"]
     #measures=["part","points","mean","median","sd","max","min"]

     #-p option for testing minimum participations and exponent formula
     if config['input_param'] == None:
!       par = [100, 0.05] #pmid, k
     else:
        par = config['input_param'].split(",")

!    mids = {1:2010, 2:2010, 3:2011, 4:2012, 5:2013}

     #verbose switch for debugging
     if config["input_verbose"]:
***************
*** 72,104 ****

     #calculate userstats only
     for city in cities:
!       print(city)
!       print("city = " + city["hash"])
!       midyear = mids[city["ID"]]
!       if not midyear: continue
!       print("midyear = " + str(midyear) + "\n")
!       if ymax == -1:
!          sql = "SELECT max FROM %swetterturnier_citystats WHERE cityID = %d"
!          cur = db.cursor()
!          cur.execute( sql % ( db.prefix, city['ID'] ) )
!          data = cur.fetchone()
!          ymax = data[0]

        for userID in userIDs:
           user = db.get_username_by_id(userID)
!          stats = db.get_stats( city['ID'], measures, userID, 0, 0, ymax=ymax, pout=int(par[0]), pmin=int(par[1]), span=span, referenz=True, midyear=midyear, verbose=verbose )
!          #stats = db.get_stats( city['ID'], measures, userID, 0, 0, verbose=verbose )

           db.upsert_stats( city['ID'], stats, userID, 0, 0 )

!    sql = "SELECT wu.user_login, %s FROM %swetterturnier_userstats us JOIN wp_users wu ON userID = wu.ID WHERE cityID=%d AND userID IN%s ORDER BY points_adj DESC LIMIT 0,50"
     cols = ",".join( measures )

     #generating ranking table output, write to .xls file
     with pd.ExcelWriter( "plots/test_list.xls" ) as writer:
        for city in cities:
!          table = pd.read_sql_query( sql % ( cols, db.prefix, city['ID'], database.sql_tuple(userIDs) ), db )
!          print(table)
           table.to_excel( writer, sheet_name=city["hash"] )

     db.commit()
--- 64,92 ----

     #calculate userstats only
     for city in cities:
!       print "city = " + city["hash"]
!       midyear = mids[city['ID']]

        for userID in userIDs:
           user = db.get_username_by_id(userID)
!          stats = db.compute_stats( city['ID'], measures, userID, 0, 0, span=span, pmid=int(par[0]), x0=float(par[1]), referenz=True, verbose=verbose, midyear=midyear )

           db.upsert_stats( city['ID'], stats, userID, 0, 0 )

!    sql = """
!       SELECT wu.user_login, %s
!       FROM %swetterturnier_userstats us
!       JOIN wp_users wu ON userID = wu.ID WHERE cityID=%d AND userID IN%s
!       ORDER BY points_adj DESC LIMIT 0,50
!    """
! 
     cols = ",".join( measures )

     #generating ranking table output, write to .xls file
     with pd.ExcelWriter( "plots/test_list.xls" ) as writer:
        for city in cities:
!          table = pd.read_sql_query( sql % ( cols, db.prefix, city['ID'], db.sql_tuple(userIDs) ), db )
!          print table
           table.to_excel( writer, sheet_name=city["hash"] )

     db.commit()

Observations.py

*** backend/Observations.py 2022-01-06 04:20:03.000000000 +0100
--- backend_old/Observations.py 2022-01-14 22:22:33.000000000 +0100
***************
*** 33,39 ****

     # - Reading WMO WW conversion file
     wmoww = utils.wmowwConversion( "wmo_ww.conf" )
!    wmoww.show()

     # - Initializing class and open database connection
     db        = database.database(config)
--- 33,39 ----

     # - Reading WMO WW conversion file
     wmoww = utils.wmowwConversion( "wmo_ww.conf" )
!    #wmoww.show()

     # - Initializing class and open database connection
     db        = database.database(config)
***************
*** 42,48 ****
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print('  * Current tournament is %s' % utils.tdate2string( tdates[0] ))
     else:
        tdates     = [config['input_tdate']]

--- 42,48 ----
     #   the bet-dates are for Saturday and Sunday.
     if config['input_tdate'] == None:
        tdates     = [db.current_tournament()]
!       print '  * Current tournament is %s' % utils.tdate2string( tdates[0] )
     else:
        tdates     = [config['input_tdate']]

***************
*** 58,65 ****
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     # ----------------------------------------------------------------
--- 58,65 ----
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

     # ----------------------------------------------------------------
***************
*** 73,88 ****
     #today = dt.datetime.fromtimestamp( today * 86400 )
     for tdate in tdates:

        tdate_int = tdate
        tdate = dt.datetime.fromtimestamp( tdate * 86400 )
!       print("    Processing data for tournament: %s (tdate=%d)" % (tdate, tdate_int))

        # ----------------------------------------------------------------
        # - Now going over the cities and compute the points. 
        # ----------------------------------------------------------------
        for city in cities:

!          print("\n  * Observations for station %s" % city['name'])

           # ----------------------------------------------------------------
           # - Looping trough tournament/bet dates.
--- 73,93 ----
     #today = dt.datetime.fromtimestamp( today * 86400 )
     for tdate in tdates:

+       check = utils.datelock(config,tdate)
+       if not config['input_force'] and check:
+          print '    Date is \'locked\' (datelock). Dont execute, skip.'
+          continue
+ 
        tdate_int = tdate
        tdate = dt.datetime.fromtimestamp( tdate * 86400 )
!       print "    Processing data for tournament: %s (tdate=%d)" % (tdate,tdate_int)

        # ----------------------------------------------------------------
        # - Now going over the cities and compute the points. 
        # ----------------------------------------------------------------
        for city in cities:

!          print "\n  * Observations for station %s" % city['name']

           # ----------------------------------------------------------------
           # - Looping trough tournament/bet dates.
***************
*** 94,101 ****
           # ----------------------------------------------------------------
           for day in range(-1,ndays):

!             date = tdate + dt.timedelta( day )
!             print("\n  * Processing observations for day: %s\n" % date)

              obs = getobs.getobs(config, db, city, date, wmoww )

--- 99,106 ----
           # ----------------------------------------------------------------
           for day in range(-1,ndays):

!             date = tdate + dt.timedelta( day ) 
!             print "\n  * Processing obsevations for day: %s\n" % date

              obs = getobs.getobs(config, db, city, date, wmoww )

***************
*** 122,131 ****
              obs.write_to_db()

     db.close()
- 
- 
- 
- 
- 
- 
- 
--- 127,129 ----

PlotsStats.py

*** backend/PlotStats.py    2022-01-06 04:20:05.000000000 +0100
--- backend_old/PlotStats.py    2022-01-14 22:22:41.000000000 +0100
***************
*** 29,35 ****
  #sigmoid = lambda x, x0, k : 1 / (1 + np.exp(-k*(x-x0)))

! def plot(db, cities, tdate):
     boxdata, hashes = [], []
     cur = db.cursor()

--- 29,35 ----
  #sigmoid = lambda x, x0, k : 1 / (1 + np.exp(-k*(x-x0)))

! def plot(db, cities, tdate, verbose=False):
     boxdata, hashes = [], []
     cur = db.cursor()

***************
*** 71,77 ****
        dates = []
        for i in tdates:
           dates.append( utils.tdate2datetime(i) )
-       if len(dates) < 2 or len(data) < 2 or len(tdates) < 2: continue

        part = data["part"    ].values
        sql = "SELECT max_part, min_part, mean_part, tdates FROM wp_wetterturnier_citystats WHERE cityID=%d"
--- 71,76 ----
***************
*** 85,91 ****
        ### PLOT PARTICIPANT COUNT (CURRENT CITY)
        fig, ax = pl.subplots()
        ax.plot_date( dates, part, marker=".", markeredgecolor="black", linestyle="-")
!       for i,col in zip(list(range(3)), ["r","b","g"]):
           ax.axhline( citystats[i], c=col )

        # format the ticks
--- 84,90 ----
        ### PLOT PARTICIPANT COUNT (CURRENT CITY)
        fig, ax = pl.subplots()
        ax.plot_date( dates, part, marker=".", markeredgecolor="black", linestyle="-")
!       for i,col in zip(range(3), ["r","b","g"]):
           ax.axhline( citystats[i], c=col )

        # format the ticks
***************
*** 134,150 ****
           x = np.array(tdates) #transform your data in a numpy array of floats
           y = np.array(median) #so the curve_fit can work

           #make the curve_fit
-          print((city['hash']))
           popt, pcov = curve_fit(func, x, y)
!          print("POLY FIT:")
!          print(("a = %s , b = %s, c = %s, d = %s" % (popt[0], popt[1], popt[2], popt[3]) ))
           stats = {"p" : popt[0], "q" : popt[1], "r" : popt[2], "s" : popt[3]}
           if i == "":
              db.upsert_stats( city["ID"], stats ) 
           eopt, ecov = curve_fit(e_func, x, y)
!          print("EXP FIT:")
!          print(("a = %s , b = %s, c = %s" % (eopt[0], eopt[1], eopt[2]) ))
           stats = {"A" : eopt[0], "B" : eopt[1], "C" : eopt[2]}
           if i == "":
              db.upsert_stats( city["ID"], stats )
--- 133,167 ----
           x = np.array(tdates) #transform your data in a numpy array of floats
           y = np.array(median) #so the curve_fit can work

+          #find missing median values (d1,d2 error in ZUR)
+          which = []
+          for ii, yi in enumerate(y):
+             if np.isnan(yi):
+                which.append(ii)
+ 
+          #for var in [x, y, dates, Qlow, Qupp, MIN, MAX, median1, median0, sd, sd_u]:
+          #   exec("var = np.delete(var, which)")
+ 
+          x = np.delete(x, which)
+          y = np.delete(y, which)
+          pdates = np.delete(dates, which)
+          Qlow, Qupp = np.delete(Qlow, which), np.delete(Qupp, which)
+          MIN, MAX   = np.delete(MIN,  which), np.delete(MAX, which)
+          median1, median0, sd, sd_u = np.delete(median1, which), np.delete(median0, which), np.delete(sd, which), np.delete(sd_u, which)
+ 
           #make the curve_fit
           popt, pcov = curve_fit(func, x, y)
!          if verbose:
!             print(city['hash'])
!             print("POLY FIT:")
!             print("a = %s , b = %s, c = %s, d = %s" % (popt[0], popt[1], popt[2], popt[3]) )
           stats = {"p" : popt[0], "q" : popt[1], "r" : popt[2], "s" : popt[3]}
           if i == "":
              db.upsert_stats( city["ID"], stats ) 
           eopt, ecov = curve_fit(e_func, x, y)
!          if verbose:
!             print("EXP FIT:")
!             print("a = %s , b = %s, c = %s" % (eopt[0], eopt[1], eopt[2]) )
           stats = {"A" : eopt[0], "B" : eopt[1], "C" : eopt[2]}
           if i == "":
              db.upsert_stats( city["ID"], stats )
***************
*** 152,164 ****
           #sopt, scov = curve_fit(sigmoid, x, y, p0=[10000, 0.005], method='dogbox' )
           #print("SIGMOID FIT:")
           #print("x0 = %s , k = %s" % (sopt[0], sopt[1]) )
-          

           ### PLOT MEDIAN
           fig, ax = pl.subplots()
!          ax.plot_date( dates, median, label="Median", linestyle="-", marker="")
!          ax.plot_date( dates, func(x, *popt), "-g", label="Poly-Fitted Curve")
!          ax.plot_date( dates, e_func(x, *eopt), "-r", label="Log-Fitted Curve")

           # format the ticks
           ax.xaxis.set_major_locator(years)
--- 169,180 ----
           #sopt, scov = curve_fit(sigmoid, x, y, p0=[10000, 0.005], method='dogbox' )
           #print("SIGMOID FIT:")
           #print("x0 = %s , k = %s" % (sopt[0], sopt[1]) )

           ### PLOT MEDIAN
           fig, ax = pl.subplots()
!          ax.plot_date( pdates, x, label="Median", linestyle="-", marker="")
!          ax.plot_date( pdates, func(x, *popt), "-g", label="Poly-Fitted Curve")
!          ax.plot_date( pdates, e_func(x, *eopt), "-r", label="Log-Fitted Curve")

           # format the ticks
           ax.xaxis.set_major_locator(years)
***************
*** 166,173 ****
           ax.xaxis.set_minor_locator(months)

           # round to nearest years.
!          datemin = np.datetime64(dates[0], 'Y')
!          datemax = np.datetime64(dates[-1], 'Y') + np.timedelta64(1, 'Y')
           ax.set_xlim(datemin, datemax)

           # format the coords message box
--- 182,189 ----
           ax.xaxis.set_minor_locator(months)

           # round to nearest years.
!          datemin = np.datetime64(pdates[0], 'Y')
!          datemax = np.datetime64(pdates[-1], 'Y') + np.timedelta64(1, 'Y')
           ax.set_xlim(datemin, datemax)

           # format the coords message box
***************
*** 185,201 ****
           fig.savefig("plots/"+city['hash']+"/median"+i, dpi=96)

           ### MEDIAN + IQR
!          ax.fill_between(dates, Qlow, Qupp, color="grey")
           ax.set_title("Median Points + IQR in "+city['name']+day)
           fig.savefig("plots/"+city['hash']+"/median_IQR"+i, dpi=96)

           ### PLOT MEDIAN + RANGE
           fig, ax = pl.subplots()
!          ax.plot_date( dates, median, label="Median", linestyle="-", marker="")
!          ax.plot_date( dates, func(x, *popt), "-g", label="Poly-Fitted Curve")
!          ax.plot_date( dates, e_func(x, *eopt), "-r", label="Log-Fitted Curve")
!          ax.fill_between(dates, MIN, MAX, color="grey", alpha=0.5)

           # format the ticks
           ax.xaxis.set_major_locator(years)
--- 201,217 ----
           fig.savefig("plots/"+city['hash']+"/median"+i, dpi=96)

           ### MEDIAN + IQR
!          ax.fill_between(pdates, Qlow, Qupp, color="grey")
           ax.set_title("Median Points + IQR in "+city['name']+day)
           fig.savefig("plots/"+city['hash']+"/median_IQR"+i, dpi=96)

           ### PLOT MEDIAN + RANGE
           fig, ax = pl.subplots()
!          ax.plot_date( pdates, x, label="Median", linestyle="-", marker="")
!          ax.plot_date( pdates, func(x, *popt), "-g", label="Poly-Fitted Curve")
!          ax.plot_date( pdates, e_func(x, *eopt), "-r", label="Log-Fitted Curve")
!          ax.fill_between( pdates, MIN, MAX, color="grey", alpha=0.5)

           # format the ticks
           ax.xaxis.set_major_locator(years)
***************
*** 203,210 ****
           ax.xaxis.set_minor_locator(months)

           # round to nearest years.
!          datemin = np.datetime64(dates[0], 'Y')
!          datemax = np.datetime64(dates[-1], 'Y') + np.timedelta64(1, 'Y')
           ax.set_xlim(datemin, datemax)

           # format the coords message box
--- 219,226 ----
           ax.xaxis.set_minor_locator(months)

           # round to nearest years.
!          datemin = np.datetime64(pdates[0], 'Y')
!          datemax = np.datetime64(pdates[-1], 'Y') + np.timedelta64(1, 'Y')
           ax.set_xlim(datemin, datemax)

           # format the coords message box
***************
*** 224,244 ****

           ### PLOT MEAN + SD
           y = np.array(mean) #so the curve_fit can work

-          print((city['hash']))
           popt, pcov = curve_fit(func, x, y)
!          print("POLY FIT:")
!          print(("a = %s , b = %s, c = %s, d = %s" % (popt[0], popt[1], popt[2], popt[3]) ))
           eopt, ecov = curve_fit(e_func, x, y, p0=[0.5,2,4])
!          print("EXP FIT:")
!          print(("a = %s , b = %s, c = %s" % (eopt[0], eopt[1], eopt[2]) ))
           #sopt, scov = curve_fit(sigmoid, x, y, p0=[10000, 0.005], method='dogbox' )

           fig, ax = pl.subplots()
!          ax.plot_date( dates, y, label="Mean", linestyle="-", marker="")
!          ax.plot_date( dates, func(x, *popt), "-g", label="Poly-Fitted Curve")
!          ax.plot_date( dates, e_func(x, *eopt), "-r", label="Log-Fitted Curve")
!          ax.fill_between(dates, y-sd, y+sd, color="grey", alpha=0.5)

           # format the ticks
           ax.xaxis.set_major_locator(years)
--- 240,264 ----

           ### PLOT MEAN + SD
           y = np.array(mean) #so the curve_fit can work
+          if which:
+             y = np.delete(y, which)

           popt, pcov = curve_fit(func, x, y)
!          if verbose:
!             print(city['hash'])
!             print("POLY FIT:")
!             print("a = %s , b = %s, c = %s, d = %s" % (popt[0], popt[1], popt[2], popt[3]) )
           eopt, ecov = curve_fit(e_func, x, y, p0=[0.5,2,4])
!          if verbose:
!             print("EXP FIT:")
!             print("a = %s , b = %s, c = %s" % (eopt[0], eopt[1], eopt[2]) )
           #sopt, scov = curve_fit(sigmoid, x, y, p0=[10000, 0.005], method='dogbox' )

           fig, ax = pl.subplots()
!          ax.plot_date( pdates, y, label="Mean", linestyle="-", marker="")
!          ax.plot_date( pdates, func(x, *popt), "-g", label="Poly-Fitted Curve")
!          ax.plot_date( pdates, e_func(x, *eopt), "-r", label="Log-Fitted Curve")
!          ax.fill_between( pdates, y-sd, y+sd, color="grey", alpha=0.5)

           # format the ticks
           ax.xaxis.set_major_locator(years)
***************
*** 246,253 ****
           ax.xaxis.set_minor_locator(months)

           # round to nearest years.
!          datemin = np.datetime64(dates[0], 'Y')
!          datemax = np.datetime64(dates[-1], 'Y') + np.timedelta64(1, 'Y')
           ax.set_xlim(datemin, datemax)

           # format the coords message box
--- 266,273 ----
           ax.xaxis.set_minor_locator(months)

           # round to nearest years.
!          datemin = np.datetime64(pdates[0], 'Y')
!          datemax = np.datetime64(pdates[-1], 'Y') + np.timedelta64(1, 'Y')
           ax.set_xlim(datemin, datemax)

           # format the coords message box
***************
*** 273,279 ****

           for dat, ylab, title, filename in zip(datas, ylabs, titles, filenames):
              fig, ax = pl.subplots()
!             ax.plot_date( dates, dat, marker=".", markeredgecolor="black", label = ylab )

              (m, n) = np.polyfit(x, dat, 1)
              yp = np.polyval([m, n], x)
--- 293,299 ----

           for dat, ylab, title, filename in zip(datas, ylabs, titles, filenames):
              fig, ax = pl.subplots()
!             ax.plot_date( pdates, dat, marker=".", markeredgecolor="black", label = ylab )

              (m, n) = np.polyfit(x, dat, 1)
              yp = np.polyval([m, n], x)
***************
*** 282,295 ****

              #insert m,b to database (citystats)
              if filename+i == "sd_upp":
!                print("SD_upp:\nm = %f | n = %f" % (m, n))
!                print("LOG FIT:")
!                print(("T = %s , U = %s, V = %s" % (eopt[0], eopt[1], eopt[2]) ))
                 stats = {"m" : m, "n" : n, "T" : eopt[0], "U" : eopt[1], "V" : eopt[2]}
                 db.upsert_stats( city["ID"], stats )

!             ax.plot_date( dates, yp, "-r", label="Linear Fit" )
!             ax.plot_date( dates, e_func(x, *eopt), "-g", label="Log-Fit" )          

              # format the ticks
              ax.xaxis.set_major_locator(years)
--- 302,316 ----

              #insert m,b to database (citystats)
              if filename+i == "sd_upp":
!                if verbose:
!                   print "SD_upp:\nm = %f | n = %f" % (m, n)
!                   print("LOG FIT:")
!                   print("T = %s , U = %s, V = %s" % (eopt[0], eopt[1], eopt[2]) )
                 stats = {"m" : m, "n" : n, "T" : eopt[0], "U" : eopt[1], "V" : eopt[2]}
                 db.upsert_stats( city["ID"], stats )

!             ax.plot_date( pdates, yp, "-r", label="Linear Fit" )
!             ax.plot_date( pdates, e_func(x, *eopt), "-g", label="Log-Fit" )          

              # format the ticks
              ax.xaxis.set_major_locator(years)
***************
*** 297,304 ****
              ax.xaxis.set_minor_locator(months)

              # round to nearest years.
!             datemin = np.datetime64(dates[0], 'Y')
!             datemax = np.datetime64(dates[-1], 'Y') + np.timedelta64(1, 'Y')
              ax.set_xlim(datemin, datemax)

              # format the coords message box
--- 318,325 ----
              ax.xaxis.set_minor_locator(months)

              # round to nearest years.
!             datemin = np.datetime64(pdates[0], 'Y')
!             datemax = np.datetime64(pdates[-1], 'Y') + np.timedelta64(1, 'Y')
              ax.set_xlim(datemin, datemax)

              # format the coords message box
***************
*** 314,319 ****
--- 335,341 ----
              ax.legend()
              fig.autofmt_xdate()
              fig.savefig("plots/"+city['hash']+"/"+filename+i, dpi=96)
+             pl.close("all")

     #save participation plot for all cities
     # format the ticks
***************
*** 338,348 ****
     figx.set_size_inches(16,9)
     figx.autofmt_xdate()
     figx.savefig("plots/parts", dpi=96)
!  
     #save boxplot for all cities
     fig, ax = pl.subplots()
!    ax.boxplot( boxdata, showfliers=False, whiskerprops = dict(linestyle='-',linewidth=3
! , color='black'), medianprops = dict(linestyle=':', linewidth=3, color='firebrick'), boxprops = dict(linestyle='-', linewidth=3, color='darkgoldenrod'), capprops=dict(linewidth=3) )
     ax.grid( True )
     ax.set_title("Boxplot of points for all cities")
     ax.set_xlabel("City")
--- 360,370 ----
     figx.set_size_inches(16,9)
     figx.autofmt_xdate()
     figx.savefig("plots/parts", dpi=96)
!    pl.close("all") 
! 
     #save boxplot for all cities
     fig, ax = pl.subplots()
!    ax.boxplot( boxdata, showfliers=False, whiskerprops = dict(linestyle='-',linewidth=3, color='black'), medianprops = dict(linestyle=':', linewidth=3, color='firebrick'), boxprops = dict(linestyle='-', linewidth=3, color='darkgoldenrod'), capprops=dict(linewidth=3) )
     ax.grid( True )
     ax.set_title("Boxplot of points for all cities")
     ax.set_xlabel("City")
***************
*** 352,357 ****
--- 374,380 ----

     fig.set_size_inches( 16,9 )
     fig.savefig("plots/boxplot", dpi=96)
+    pl.close("all")

     #plot of mean+sd to compare difficulty of all cities
     meancities, sdcities = [], []
***************
*** 371,377 ****

     fig.set_size_inches( 16,9 )
     fig.savefig("plots/mean_sd", dpi=96)
! 

  # - Start as main script (not as module)
  # -------------------------------------------------------------------
--- 394,400 ----

     fig.set_size_inches( 16,9 )
     fig.savefig("plots/mean_sd", dpi=96)
!    pl.close("all")

  # - Start as main script (not as module)
  # -------------------------------------------------------------------
***************
*** 396,413 ****
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for i in cities:
!          if i['name'] == config['input_city']: tmp.append( i )
        cities = tmp

     if config['input_tdate'] == None:
        tdate     = db.current_tournament()
!       print('  * Current tournament is %s' % utils.tdate2string( tdate ))
     else:
        tdate = config['input_tdate']

     # - Calling the function now
!    plot(db, cities, tdate)

     db.commit()
     db.close()
--- 419,440 ----
     # - If input city set, then drop all other cities.
     if not config['input_city'] == None:
        tmp = []
!       for elem in cities:
!          if elem['name'] == config['input_city']: tmp.append( elem )
        cities = tmp

+    if config['input_verbose'] == None:
+       verbose = False
+    else: verbose = config['input_verbose']
+ 
     if config['input_tdate'] == None:
        tdate     = db.current_tournament()
!       print '  * Current tournament is %s' % utils.tdate2string( tdate )
     else:
        tdate = config['input_tdate']

     # - Calling the function now
!    plot(db, cities, tdate, verbose=verbose)

     db.commit()
     db.close()

Rerun.py

*** backend/Rerun.py    2022-01-06 04:20:14.000000000 +0100
--- backend_old/Rerun.py    2022-01-14 22:22:50.000000000 +0100
***************
*** 17,23 ****
  # - Start as main script (not as module)
  if __name__ == '__main__':
     """
!    This is Chain.py, a simple controlling script. Starts several
     script in the order as they have to be called to compute all
     necessary things for the wetterturnier. E.g., including:
     - ComputeMeanBets.py  (compute group bets)
--- 17,23 ----
  # - Start as main script (not as module)
  if __name__ == '__main__':
     """
!    This is Rerun.py, a simple controlling script. Starts several
     script in the order as they have to be called to compute all
     necessary things for the wetterturnier. E.g., including:
     - ComputeMeanBets.py  (compute group bets)
***************
*** 45,51 ****
     db = database.database(config)

     if not db.check_if_table_exists("wetterturnier_rerunrequest"):
!       print("[!] Table wetterturnier_rerunrequest does not exist, stop here.")
        db.close(); sys.exit(9)

     # - Check whether there are any rerun requests
--- 45,51 ----
     db = database.database(config)

     if not db.check_if_table_exists("wetterturnier_rerunrequest"):
!       print "[!] Table wetterturnier_rerunrequest does not exist, stop here."
        db.close(); sys.exit(9)

     # - Check whether there are any rerun requests
***************
*** 54,69 ****
                 "WHERE done IS NULL GROUP BY tdate,cityID;")
     rerun = cur.fetchall()

!    if not rerun:
!       print("   There are no rerun requests, stop here."); sys.exit(0)

     # - Compute the Points for all the dudes first
     import subprocess as sub
     from datetime import datetime as dt
     scripts = ['ComputeMeanBets.py',
                'ComputePetrus.py',
!               #'ComputeMoses.py',
!               'ComputePersistenzen.py',
                'ComputePoints.py',
                'ComputeSumPoints.py',
                'ComputeSleepy.py']
--- 54,68 ----
                 "WHERE done IS NULL GROUP BY tdate,cityID;")
     rerun = cur.fetchall()

!    if len(rerun) == 0:
!       print "   There are no rerun requests, stop here."; sys.exit(0)

     # - Compute the Points for all the dudes first
     import subprocess as sub
     from datetime import datetime as dt
     scripts = ['ComputeMeanBets.py',
                'ComputePetrus.py',
! #              'ComputePersistenzen.py',
                'ComputePoints.py',
                'ComputeSumPoints.py',
                'ComputeSleepy.py']
***************
*** 71,87 ****

     # - Now calling the other scripts using the necessary
     #   input arguments.
!    for re in rerun:
!       tdate    = int( re[0] )
        tdatestr = dt.fromtimestamp(tdate*86400).strftime("%Y-%m-%d") 
!       cityID   = int( re[1] )

        city     = db.get_city_name_by_ID( cityID )
        if not city:
!          print("[!] OUPS! Cannot find city {0:d} in database!".format(cityID))

!       print("  * Rerun for tournament date {0:d} ({1:s})".format(tdate,tdatestr))
!       print("    Run computation for city {0:s} ({1:d})".format(city,cityID))

        # Run the scripts in the correct order
        for script in scripts:
--- 70,86 ----

     # - Now calling the other scripts using the necessary
     #   input arguments.
!    for rec in rerun:
!       tdate    = int(rec[0])
        tdatestr = dt.fromtimestamp(tdate*86400).strftime("%Y-%m-%d") 
!       cityID   = int(rec[1])

        city     = db.get_city_name_by_ID( cityID )
        if not city:
!          print "[!] OUPS! Cannot find city {0:d} in database!".format(cityID)

!       print "  * Rerun for tournament date {0:d} ({1:s})".format(tdate,tdatestr)
!       print "    Run computation for city {0:s} ({1:d})".format(city,cityID)

        # Run the scripts in the correct order
        for script in scripts:
***************
*** 97,103 ****
           p1 = sub.Popen(cmd,stderr=sub.PIPE)
           err = p1.communicate()
           if not p1.returncode == 0:
!             for line in err: print('%s\n' % line)
              utils.exit('ERROR WHILE RUNNING %s AS SUBPROCESS FOR DATE %d CITY %s' % (script,tdate,city))

--- 96,102 ----
           p1 = sub.Popen(cmd,stderr=sub.PIPE)
           err = p1.communicate()
           if not p1.returncode == 0:
!             for line in err: print '%s\n' % line
              utils.exit('ERROR WHILE RUNNING %s AS SUBPROCESS FOR DATE %d CITY %s' % (script,tdate,city))

TestPoints.py

*** backend/TestPoints.py   2022-01-06 04:20:14.000000000 +0100
--- backend_old/TestPoints.py   2022-01-14 22:22:50.000000000 +0100
***************
*** 84,92 ****

     inputs, args = parser.parse_args()
     # - Missing input -o
!    if not inputs.param:  print(parser.usage);    utils.exit( "Missing required input -p/--param.")
!    if not inputs.obs:    print(parser.usage);    utils.exit( "Missing required input -o/--obs.")
!    if not inputs.values: print(parser.usage);    utils.exit( "Missing required input -v/--values.")
     # ----------------------------------------------------------------

--- 84,92 ----

     inputs, args = parser.parse_args()
     # - Missing input -o
!    if not inputs.param:  print parser.usage;    utils.exit( "Missing required input -p/--param.")
!    if not inputs.obs:    print parser.usage;    utils.exit( "Missing required input -o/--obs.")
!    if not inputs.values: print parser.usage;    utils.exit( "Missing required input -v/--values.")
     # ----------------------------------------------------------------

***************
*** 100,106 ****
     # - Checking if parameter is allowed
     # ----------------------------------------------------------------
     from pywetterturnier import database
!    if not inputs.quiet: print("  * Checking if parameter %s is allowed" % inputs.param)
     db = database.database(config)
     paramID = db.get_parameter_id( inputs.param )
     db.close(False)
--- 100,106 ----
     # - Checking if parameter is allowed
     # ----------------------------------------------------------------
     from pywetterturnier import database
!    if not inputs.quiet: print "  * Checking if parameter %s is allowed" % inputs.param
     db = database.database(config)
     paramID = db.get_parameter_id( inputs.param )
     db.close(False)
***************
*** 124,132 ****
        if not x: return np.asarray([])
        tmp = x.split(",")
        res = []
!       for i in tmp:
           try:
!             res.append( float(i) )
           except:
              utils.exit("Problems: %s have to be numeric!" % msg)
        return np.asarray(res)
--- 124,132 ----
        if not x: return np.asarray([])
        tmp = x.split(",")
        res = []
!       for elem in tmp:
           try:
!             res.append( float(elem) )
           except:
              utils.exit("Problems: %s have to be numeric!" % msg)
        return np.asarray(res)
***************
*** 145,156 ****
     #   dynamic load. If not loadable, exit.
     # ----------------------------------------------------------------
     modname = "pywetterturnier.judgingclass%s" % config['judging_test']
!    if not inputs.quiet: print("  * Try to load test-judgingclass from module %s" % modname)
     try:
        from importlib import import_module 
        judging = import_module(modname)
     except Exception as e:
!       print(e)
        utils.exit("Problems loading the judgingclass %s" % modname)

     # - Initialize judging
--- 145,156 ----
     #   dynamic load. If not loadable, exit.
     # ----------------------------------------------------------------
     modname = "pywetterturnier.judgingclass%s" % config['judging_test']
!    if not inputs.quiet: print "  * Try to load test-judgingclass from module %s" % modname
     try:
        from importlib import import_module 
        judging = import_module(modname)
     except Exception as e:
!       print e
        utils.exit("Problems loading the judgingclass %s" % modname)

     # - Initialize judging
***************
*** 179,193 ****
     # - Show output
     # ----------------------------------------------------------------
     if not inputs.quiet:
!       print('\n  * Observations were:  ', end=' ')
!       for o in inputs.obs: print('%8.3f ' % (o), end=' ')
!       print('')
        for i in range(len(inputs.values)):
!          print('    - Forecast %8.3f leads to %5.2f points' % (inputs.values[i],points[i])) 
     else:
!       print('points')
        for i in range(len(inputs.values)):
!          print('%5.2f' % (points[i])) 
! 
! 
! 
--- 179,190 ----
     # - Show output
     # ----------------------------------------------------------------
     if not inputs.quiet:
!       print '\n  * Observations were:  ',
!       for o in inputs.obs: print '%8.3f ' % (o),
!       print ''
        for i in range(len(inputs.values)):
!          print '    - Forecast %8.3f leads to %5.2f points' % (inputs.values[i],points[i]) 
     else:
!       print 'points'
        for i in range(len(inputs.values)):
!          print '%5.2f' % (points[i])

mtest

*** backend/mtest.py    2022-01-06 04:20:03.000000000 +0100
--- backend_old/mtest.py    2022-01-14 22:22:33.000000000 +0100
***************
*** 3,9 ****

  # Liste aller moeglichen Argumente bzw. Staedte
  tournaments = ["bpw", "wpw", "zpw", "ipw", "lpw"]
! #tournaments = ["bpw"]
  #m.moses.processmoses("bpw")
  # fuer jede Stadt einzeln das Fortran-Programm aufrufen
  for t in tournaments:
--- 3,9 ----

  # Liste aller moeglichen Argumente bzw. Staedte
  tournaments = ["bpw", "wpw", "zpw", "ipw", "lpw"]
! #tournaments = ["wpw"]
  #m.moses.processmoses("bpw")
  # fuer jede Stadt einzeln das Fortran-Programm aufrufen
  for t in tournaments:

Voting.py

*** backend/Voting.py   2022-01-06 04:30:21.000000000 +0100
--- backend_old/Voting.py   2022-01-14 22:29:47.000000000 +0100
***************
*** 1,21 ****
- # -------------------------------------------------------------------
- # - NAME:        ComputePoints.py
- # - AUTHOR:      Reto Stauffer
- # - DATE:        2014-09-21
- # - LICENSE: GPL-3, Reto Stauffer, copyright 2014
- # -------------------------------------------------------------------
- # - DESCRIPTION: Compute points for all players. 
- # -------------------------------------------------------------------
- # - EDITORIAL:   2014-09-19, RS: Created file on thinkreto.
- #                Adapted from ComputePetrus.py
- # -------------------------------------------------------------------
- # - L@ST MODIFIED: 2018-01-19 15:20 on marvin
- # -------------------------------------------------------------------
- 
- import sys, os
- sys.path.append('PyModules')
- 
- 
  # - Start as main script (not as module)
  if __name__ == '__main__':

--- 1,3 ----
***************
*** 36,59 ****
     for i in ("Automaten", "Referenztipps", "MM-MOS", "WAV2", "Aviatik"):
        group_users = db.get_users_in_group( group=i )
        for j in group_users:
!          excluded_users.append(j)

!    print(excluded_users)

!    sql = "SELECT user_login FROM %susers WHERE ID NOT IN %s %sORDER BY user_login ASC"

     skip = str("")
     for i in ("GRP_%", "Acinn%", "%-MOS%"):
        skip += "AND user_login NOT LIKE '%s' " %i

!    cur = db.cursor()
!    cur.execute( sql % ( db.prefix, db.sql_tuple( excluded_users ), skip[:-1] ) )
     data = cur.fetchall()

     data = data[:t]

     for i in data:
!       print(i[0])

     count = len(data)

--- 18,69 ----
     for i in ("Automaten", "Referenztipps", "MM-MOS", "WAV2", "Aviatik"):
        group_users = db.get_users_in_group( group=i )
        for j in group_users:
!          excluded_users.append( int(j) )
! 
!    #find out which users have at least played once in wetterturnier
!    sql = "SELECT DISTINCT userID FROM %swetterturnier_betstat"
!    cur = db.cursor()
!    cur.execute( sql % db.prefix )
!    data = cur.fetchall()

!    users_played = []
!    for i in data:
!       print(int(i[0]))
!       users_played.append( int(i[0]) )

!    #who of them did actually play this year?
!    sql = "SELECT userID FROM %swetterturnier_betstat WHERE tdate >= 18264 AND userID IN %s ORDER BY userID ASC"
!    cur.execute( sql % (db.prefix, db.sql_tuple( users_played) ) )
!    data = cur.fetchall()
!    
!    users_played = []
!    part = 0
!    pre = data[0][0]
! 
!    for i in data:
!       if i == pre:
!          part += 1
!       if part >= 20:
!          users_played.append( int(i[0]) )
!          part = 1
!          continue
!       pre = np.copy(i)
! 
!    print( excluded_users )
! 
!    sql = "SELECT user_login FROM %susers WHERE ID NOT IN %s %sAND ID IN %s ORDER BY user_login ASC"

     skip = str("")
     for i in ("GRP_%", "Acinn%", "%-MOS%"):
        skip += "AND user_login NOT LIKE '%s' " %i

!    cur.execute( sql % ( db.prefix, db.sql_tuple( excluded_users ), skip[:-1], db.sql_tuple( users_played ) ) )
     data = cur.fetchall()

     data = data[:t]

     for i in data:
!       print( i[0] )

     count = len(data)

***************
*** 70,77 ****

     sql = "UPDATE %spostmeta SET meta_value='%s' WHERE post_id=%s AND `meta_key` = '_poll_responses'"

!    print(post_id)

-    cur = db.cursor()
     cur.execute( sql % ( db.prefix, _poll_responses, post_id ) )
     db.commit()
--- 80,87 ----

     sql = "UPDATE %spostmeta SET meta_value='%s' WHERE post_id=%s AND `meta_key` = '_poll_responses'"

!    print( int(post_id) )

     cur.execute( sql % ( db.prefix, _poll_responses, post_id ) )
     db.commit()
+ 
mammatus95 commented 2 years ago

judgingclass20021206.py

*** 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
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 

only important changes (exluding min,max,print())

***************
*** 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.
mammatus95 commented 2 years ago

mitteltip.py

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