Skip to content

Instantly share code, notes, and snippets.

@H4ckerxx44
Created August 30, 2023 18:04
Show Gist options
  • Save H4ckerxx44/fc9d681f19bef083e13d0c64ac815e9c to your computer and use it in GitHub Desktop.
Save H4ckerxx44/fc9d681f19bef083e13d0c64ac815e9c to your computer and use it in GitHub Desktop.
Kerbal Space Program 2 - Update History
from datetime import date, timedelta
title = "KSP2 Update history"
spacer = "=" * len(title) * 2
class Update:
def __init__(self, version: str, _date: date):
self.version = version
self.date = _date
self.today = _date.today()
def days_since_release(self):
diff = self.today - self.date
return f"{diff.days} days since release"
def compare_against(self, other: "Update") -> timedelta:
diff = abs(self.date - other.date)
return diff
def __repr__(self):
return f"{self.version}"
v0_1_0_0_20892 = Update("v0.1.0.0.20892", date(year=2023, month=2, day=24))
v0_1_1_0_21572 = Update("v0.1.1.0.21572", date(year=2023, month=3, day=16))
v0_1_2_0_22258 = Update("v0.1.2.0.22258", date(year=2023, month=4, day=12))
v0_1_3_0_24321 = Update("v0.1.3.0.24321", date(year=2023, month=6, day=22))
v0_1_3_1_24603 = Update("v0.1.3.1.24603", date(year=2023, month=6, day=29))
v0_1_3_2_24841 = Update("v0.1.3.2.24841", date(year=2023, month=7, day=11))
v0_1_4_0_26521 = Update("v0.1.4.0.25621", date(year=2023, month=8, day=30))
HIDDEN_UPDATES = [v0_1_3_1_24603, v0_1_3_2_24841]
MAJOR_UPDATES = [v0_1_0_0_20892, v0_1_1_0_21572, v0_1_2_0_22258, v0_1_3_0_24321, v0_1_4_0_26521]
FIRST_UPDATE = MAJOR_UPDATES[0]
LAST_UPDATE = MAJOR_UPDATES[-1]
def show_time_between_update_x_y_all():
for update_i in range(1, len(MAJOR_UPDATES)):
prev_update = MAJOR_UPDATES[update_i - 1]
now_update = MAJOR_UPDATES[update_i]
time_since = now_update.compare_against(prev_update)
print(f"time between: {prev_update.version} -- {now_update.version} = {time_since.days} days")
def total_major_updates():
return len(MAJOR_UPDATES)
def total_hidden_updates():
return len(HIDDEN_UPDATES)
def mean_days_between_updates():
all_days = []
for update_i in range(1, len(MAJOR_UPDATES)):
prev = MAJOR_UPDATES[update_i - 1]
now = MAJOR_UPDATES[update_i]
days_between = now.compare_against(prev).days
all_days.append(days_between)
return round(sum(all_days) / len(all_days), 2)
def list_all_updates():
s = ''.join(f"{i+1}. {update.version}\n" for i, update in enumerate(MAJOR_UPDATES))
# remove last \n from string
ret = s[0:len(s)-1]
return ret
def predicted_next_update_date():
now = date.today()
mean_days = round(mean_days_between_updates())
predicted = now + timedelta(days=mean_days)
return predicted
def date_to_iso(date_to_format):
return date_to_format.strftime('%Y-%m-%d')
def main():
print(title)
print(spacer)
print(list_all_updates())
print(f"Total updates: {total_major_updates()} ({total_hidden_updates()} updates hidden)")
print("")
print("Time from update x to update y")
print(spacer)
show_time_between_update_x_y_all()
print(f"Mean days between: {mean_days_between_updates()}")
print(spacer)
print(f"Predicted next update date: {date_to_iso(predicted_next_update_date())}")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment