Created
January 27, 2024 21:13
-
-
Save tigercoding56/c5f028117df68950e750e6cfd07d3b15 to your computer and use it in GitHub Desktop.
encoder for utility i am making for O.RKS , optimised for encoding XC workouts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def encode(hour,minute,second,distance):#hour from 0-9 distance meters | |
hour=min(max(0,hour),9)*10000 | |
minute=min(max(0,minute),60)*100 | |
second=min(max(0,second),60) | |
distance=max(min(1609.344*32,distance),0) | |
return chr(hour+minute+second)+chr(int(distance))+chr(int(time.localtime().tm_year))+chr(int(time.localtime().tm_yday)) | |
def decode(s): | |
time=ord(s[0]) | |
dist=ord(s[1]) | |
hour=int(time/10000) | |
minute = (int((time-hour)/100)) | |
second = (int((time-hour-minute)/10)) | |
year=ord(s[2]) | |
day=ord(s[3]) | |
return f"hour {hour} minute {minute} second {second |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment