HattrickOrganizer icon indicating copy to clipboard operation
HattrickOrganizer copied to clipboard

[FEATURE] determine gate opening for promotion/demotion on the server side

Open akasolace opened this issue 5 years ago • 2 comments

HO should allow sending data for promotion/demotion on the Tuesday following the last match of the season. I am not sure how this is implemented. Maybe going forward, we could automtize this on the server side: - Tuesday at midnight: automatic reset of database, and allowing data push - HO would then not determine by itself if data can be putched it would fetch information from the server or maybe a mix of both (like if match day = 14 check on server otherwise return false) - the message on the website would also be automatized

akasolace avatar Aug 30 '20 10:08 akasolace

  • in HO!: replace isActive() by the following logic (https://github.com/akasolace/HO/blob/b006955587a154feddecce687e5bb55cec0a0376/src/main/java/module/series/promotion/LeaguePromotionHandler.java#L50)

    • if week < 14 pass
    • elif week = 14 or (week = 15 and weekday = Monday) => display message "data will be available from the {week=15 and weekday = Tueday}"
    • else => display current message

also supportedLeagues => I think now all leagues are supported, we may remove this ----

  • on the server:
    • adapt the message similar to HO
from datetime import date, timedelta

SEASONS_OFFSET = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: -11, 11: 0, 12: 0, 14: -11, 15: -12, 16: -12, 17: -12, 18: -12, 19: -12, 20: -12, 21: -12, 22: -12, 23: -12, 24: -12, 25: -12, 26: -12, 27: -12, 28: -12, 29: -12, 30: -12, 31: -12, 32: -12, 33: -12, 34: -12, 35: -12, 36: -12, 37: -12, 38: -13, 39: -13, 44: -13, 45: -13, 46: -13, 47: -13, 50: -15, 51: -15, 52: -15, 53: -15, 54: -15, 55: -15, 56: -15, 57: -15, 58: -15, 59: -16, 60: -16, 61: -16, 62: -16, 63: -16, 64: -16, 66: -18, 67: -18, 68: -18, 69: -18, 70: -18, 71: -18, 72: -20, 73: -20, 74: -20, 75: -20, 76: -20, 77: -20, 79: -21, 80: -21, 81: -21, 83: -21, 84: -21, 85: -21, 88: -21, 89: -21, 91: -22, 93: -22, 94: -22, 95: -22, 96: -22, 97: -22, 98: -23, 99: -23, 100: -23, 101: -23, 102: -23, 103: -23, 104: -24, 105: -24, 106: -24, 107: -24, 110: -25, 111: -25, 112: -25, 113: -25, 117: -26, 118: -26, 119: -26, 120: -26, 121: -26, 122: -26, 123: -27, 124: -27, 125: -27, 126: -27, 127: -28, 128: -28, 129: -28, 130: -29, 131: -29, 132: -29, 133: -30, 134: -30, 135: -32, 136: -32, 137: -32, 138: -32, 139: -33, 140: -33, 141: -34, 142: -34, 143: -35, 144: -35, 145: -44, 146: -44, 147: -44, 148: -44, 149: -69, 151: -69, 152: -69, 153: -69, 154: -69, 155: -72, 156: -72, 157: -74, 158: -74, 159: -74, 160: -74, 1000: -63}

def gregorianToHT(_date, useLocal = False, iLeagueID=None):

    ORIGIN = date(1997, 6, 2)
    dayDiff = (_date-ORIGIN).days
    season = dayDiff // 112
    week = (dayDiff % 112 // 7) + 1

    if useLocal:
        assert iLeagueID is not None, "if useLocal = True, iLeagueID should be provided"
        season += SEASONS_OFFSET[iLeagueID]

    return season, week


def htToGregorian(iSeasaon, iWeek, useLocal=False, iLeagueID=None):

    assert 0 < iWeek < 17, "iWeek should be between 1 and 16 included"
    assert 0 < iSeasaon, "iSeasaon should be positive"

    ORIGIN = date(1997, 6, 2)

    if useLocal:
        assert iLeagueID is not None, "if useLocal = True, iLeagueID should be provided"
        iSeasaon -= SEASONS_OFFSET[iLeagueID]

    dayDiff = (iSeasaon) * 112 + (iWeek-1) * 7

    return ORIGIN + timedelta(days=dayDiff)


# some tests ================================================================================================
assert gregorianToHT(date(2020, 6, 27)) == (75, 4)
assert gregorianToHT(date(2018, 5, 10)) == (68, 5)
assert gregorianToHT(date(2009, 5, 28)) == (39, 2)
assert gregorianToHT(date(2020, 8, 31), True, 52) == (60, 14)
assert htToGregorian(75, 1) + timedelta(days=5) == date(2020, 6, 6)
assert htToGregorian(75, 4) + timedelta(days=5) == date(2020, 6, 27)
assert htToGregorian(75, 14) + timedelta(days=5) == date(2020, 9, 5)
assert htToGregorian(75, 15) == date(2020, 9, 7)
assert htToGregorian(75, 16) == date(2020, 9, 14)
assert htToGregorian(76, 1) == date(2020, 9, 21)
assert htToGregorian(68, 5) == date(2018, 5, 7)
assert htToGregorian(39, 2) == date(2009, 5, 25)
assert htToGregorian(60, 14, True, 52) == date(2020, 8, 31)



akasolace avatar Aug 31 '20 13:08 akasolace

I think HTCalendar.java and HTCalendarFactory.java are not correctly implemented but touching that low-level part of the code might have some bad side effect

akasolace avatar Sep 01 '20 08:09 akasolace

HOServer is disabled

wsbrenk avatar Oct 22 '23 14:10 wsbrenk