diff options
| -rw-r--r-- | aslclass.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/aslclass.py b/aslclass.py index 174f15d..d3c499e 100644 --- a/aslclass.py +++ b/aslclass.py @@ -3,9 +3,9 @@ # Licensed under the Apache License, Version 2.0 # http://www.apache.org/licenses/LICENSE-2.0 -# ---Version 2.3--- - +# ---Version 2.3.0--- +# imports import sys import os import msvcrt @@ -21,8 +21,10 @@ class ASLreport: self.shotlist=[] self.totaltime=0 + # begin def metadata(self): load=input("Do you want to start a new state? (y/n +enter) (n=load state)\n") + # load a file or start a new state? if load=='y': pass elif load=='n': self.loader() self.name=input("\nEnter movie name:\n") @@ -37,14 +39,18 @@ class ASLreport: pathlist=os.listdir(".") print(pathlist) serial=input("Enter the serial number of the savefile (starts from 0)\n") + # if the filetype does not have the required extension if listpaths('.')[int(serial)][-9:len(listpaths('.')[int(serial)])]!="savestate": sys.exit("unknown filetype") loader=open(listpaths('.')[int(serial)], mode="r").read() + # loading algorithm: search for required values with regex data=re.search(r"(?P<MovieName>.+)\n(?P<TotalTime>.+)\n(?P<ShotCount>\d+)",loader) + # assign values try: self.name=data.group('MovieName') self.totaltime=float(data.group('TotalTime')) self.shotcount=int(data.group('ShotCount')) + # .savestate file with incorrect or corrupt data except AttributeError: sys.exit("unknown filetype") print("press enter to start loaded state") @@ -57,14 +63,17 @@ class ASLreport: def key(self): clock() tottime=0 + # wait for keystroke keystroke=str(msvcrt.getch())[-2] if keystroke=="s": + # shot detected timestamp=clock() self.shotcount=self.shotcount+1 if self.pauseinterval!=[]: + # if 'pause' has never been used before for pausetime in self.pauseinterval: tottime=tottime+pausetime actualtime=float(timestamp)-float(tottime) - # self.shotlist.append((self.shotcount,actualtime )) + self.shotlist.append((self.shotcount,actualtime )) print("Shot #%d at %fs "%(self.shotcount,actualtime)) else: self.shotlist.append((self.shotcount,timestamp )) @@ -81,6 +90,7 @@ class ASLreport: if startagain=="p": self.endpause=clock() print("restarted") + # the next line will help to calculate the total time by keeping track of time lost in pauses self.pauseinterval.append(self.endpause-self.startpause) self.key() elif startagain=="e": self.reset() @@ -90,9 +100,11 @@ class ASLreport: print('\n==ASLreport for "%s"=='%self.name) self.totaltime=clock() for pausetime in self.pauseinterval: + # subtract pausetime from the totaltime of the session self.totaltime=self.totaltime-pausetime print(self.totaltime) try: self.totaltime/self.shotcount + # if shotcount is 0 except ZeroDivisionError: sys.exit("no shots recorded") self.ASL=self.totaltime/self.shotcount print("number of shots=%d"%self.shotcount) @@ -107,10 +119,11 @@ class ASLreport: "ASL report for %s \n\n Record Time=%f\n Recorded Shots=%d\n ASL=%f\nShot Timestamps:\n%s"%(self.name,self.totaltime,self.shotcount,self.ASL,str(self.shotlist))) def savestate(self): + # open and write a '.savestate' file with the required data and in a specific format saver=open("%s.savestate"%self.name, mode="w") saver.write("%s\n%f\n%f"%(self.name,self.totaltime,self.shotcount)) - +# --main boilerplate-- if __name__=="__main__": ASLreport().metadata()
\ No newline at end of file |
