Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery Starbot ⭐ refactored NicolasFlandrois/Stardate #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions sdcompute.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,78 +21,83 @@ def config():
with open("sdconfig.json") as f:
return json.load(f)

def ask_integer(message: str, range, error_message: str = ""):
def ask_integer(self, range, error_message: str = ""):
"""
This function's purpose is to ask and verify an Integer.
"""
var = None
while True:
try:
var = int(input(message))
var = int(input(self))
if var in range:
return var
raise

Comment on lines -24 to -35
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Compute.ask_integer refactored with the following changes:

except KeyboardInterrupt:
break

except:
print(error_message)

def leapyr(year: int):
def leapyr(self):
""""
This function defines if the year is
a Leap year (366 days)
or a Normal year (365 days).
Then it will to the variable n the value of 366 or 365, accordingly.
"""
if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):
n = 366
# print("The year is a Leap year.\n")

else:
n = 365
# print("The year is a normal year.\n")

return n
return 366 if self % 400 == 0 or self % 4 == 0 and self % 100 != 0 else 365
Comment on lines -42 to +47
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Compute.leapyr refactored with the following changes:

This removes the following comments ( why? ):

# print("The year is a Leap year.\n")
# print("The year is a normal year.\n")


def nowearthdate():
"""Will generate automaticaly a tuple datetime object, for now time"""
nowdate = datetime.datetime.now()
return nowdate.timetuple(), nowdate.strftime('%A, %Y %B %d. %H:%M:%S')

def sdconvert(t):
def sdconvert(self):
Comment on lines -64 to +54
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Compute.sdconvert refactored with the following changes:

"""
Stardate calculator
t = Time (cf 'datetime.datetime.now().timetuple()' format)
Compute.config()["earthdate"] = Earthdate Year reference point
Compute.config()["stardate"] = Stardate Yaer reference point
Compute.leapyr(t.tm_year) = number of days leap year/not (365 or 366)
"""
return format(((Compute.config()["stardate"] +
(1000*(t.tm_year - Compute.config()["earthdate"]))) +
((1000/((Compute.leapyr(t.tm_year))*1440.0))*(((
t.tm_yday - 1.0)*1440.0) +
(t.tm_hour*60.0) + t.tm_min))), '.2f')
return format(
(
Compute.config()["stardate"]
+ 1000 * (self.tm_year - Compute.config()["earthdate"])
)
+ (
1000
/ (Compute.leapyr(self.tm_year) * 1440.0)
* (
(
(((self.tm_yday - 1.0) * 1440.0) + self.tm_hour * 60.0)
+ self.tm_min
)
)
),
'.2f',
)

def sdtranslate(sd):
def sdtranslate(self):
Comment on lines -78 to +80
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Compute.sdtranslate refactored with the following changes:

"""
Stardate translator
sd = Stardate Time (cf float, stardate format)
Compute.config()["earthdate"] = Earthdate Year reference point
Compute.config()["stardate"] = Stardate Yaer reference point
Compute.leapyr(t.tm_year) = number of days leap year/not (365 or 366)
"""
print("Stardate : ", sd)
print("Stardate : ", self)

dlist = []
ed_year = int(((sd - Compute.config()["stardate"]) // 1000) +
Compute.config()["earthdate"])
dlist.append(int(ed_year))
ed_time = (((sd - Compute.config()["stardate"]) % 1000) /
(1000 / (1440*Compute.leapyr(ed_year))))
ed_year = int(
(self - Compute.config()["stardate"]) // 1000
+ Compute.config()["earthdate"]
)
ed_time = (
(self - Compute.config()["stardate"])
% 1000
/ (1000 / (1440 * Compute.leapyr(ed_year)))
)
ed_day = (ed_time//1440)+1
dlist.append(int(ed_day))
dlist = [ed_year, int(ed_day)]
ed_hour = (ed_time-((ed_day-1)*1440))//60
dlist.append(int(ed_hour))
ed_min = ed_time % 60
Expand Down
59 changes: 30 additions & 29 deletions sdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def clean():
"""
os.system("cls" if platform.system() == "Windows" else "clear")

def menu(convert, translate):
def menu(self, translate):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function View.menu refactored with the following changes:

"""menu docstring"""
View.clean()
print("STARDATE\n")
Expand All @@ -40,27 +40,26 @@ def menu(convert, translate):
View.clean()

try:
if responce.strip().lower() in ['r', 'q', '1', '2', '3']:
if responce.strip().lower() == 'r':
continue
elif responce.strip().lower() == 'q':
break
elif responce.strip().lower() == '1':
View.clean()
View.show_today_stardate()
print('\n')
elif responce.strip().lower() == '2':
View.clean()
date = View.ask_date()
stardate = Compute.sdconvert(date[0])
View.show_stardate(stardate, date[1])
print('\n')
elif responce.strip().lower() == '3':
View.clean()
print("\nEarthdate : ", translate(View.ask_stardate()))
print('\n')
else:
raise
if responce.strip().lower() not in ['r', 'q', '1', '2', '3']:
raise
if responce.strip().lower() == 'r':
continue
elif responce.strip().lower() == 'q':
break
elif responce.strip().lower() == '1':
View.clean()
View.show_today_stardate()
print('\n')
elif responce.strip().lower() == '2':
View.clean()
date = View.ask_date()
stardate = Compute.sdconvert(date[0])
View.show_stardate(stardate, date[1])
print('\n')
elif responce.strip().lower() == '3':
View.clean()
print("\nEarthdate : ", translate(View.ask_stardate()))
print('\n')
else:
raise
except:
Expand All @@ -70,9 +69,11 @@ def ask_date():
"""
Ask input and return for the date object.
"""
dlist = []
dlist.append(Compute.ask_integer("Earth Year? (YYYY format) ",
range(-10000000, 10000000)))
dlist = [
Compute.ask_integer(
"Earth Year? (YYYY format) ", range(-10000000, 10000000)
)
]
Comment on lines -73 to +76
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function View.ask_date refactored with the following changes:

dlist.append(Compute.ask_integer("Earth Month? (from 01 to 12) ",
range(1, 13)))
dlist.append(Compute.ask_integer("Day of the month? (from 01 to 31) ",
Expand All @@ -98,18 +99,18 @@ def ask_stardate():
View.clean()
return stardate

def show_date(earthdate):
def show_date(self):
"""
Displays a date object, in a User Experience readable format.
"""
return earthdate()[1]
return self()[1]
Comment on lines -101 to +106
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function View.show_date refactored with the following changes:


def show_stardate(stardate, date):
def show_stardate(self, date):
"""
Displays Date's Stardate.
"""
print("Earthdate : ", date)
print("\nStardate : ", stardate)
print("\nStardate : ", self)
Comment on lines -107 to +113
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function View.show_stardate refactored with the following changes:


def show_today_stardate():
"""
Expand Down