Improve seconds conversion code... slightly...
This commit is contained in:
		
							parent
							
								
									f5c39076fd
								
							
						
					
					
						commit
						20218372d5
					
				| 
						 | 
					@ -22,37 +22,23 @@ class LogEntry(object):
 | 
				
			||||||
                             f"duration: {self.duration}",
 | 
					                             f"duration: {self.duration}",
 | 
				
			||||||
                             f"file_count: {self.file_count}"])
 | 
					                             f"file_count: {self.file_count}"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # def datetime_string(self):
 | 
					    def get_duration(self, duration_string):
 | 
				
			||||||
    #     s = self.start_time
 | 
					 | 
				
			||||||
    #     return "%04d-%02d-%02d %02d:%02d:%02d" % (s.year, s.month, s.day,
 | 
					 | 
				
			||||||
    #                                               s.hour, s.minute, s.second)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @staticmethod
 | 
					 | 
				
			||||||
    def get_duration(duration_string):
 | 
					 | 
				
			||||||
        total_seconds = 0.0
 | 
					        total_seconds = 0.0
 | 
				
			||||||
 | 
					        time_strings = [('second', 1), ('minute', 60), ('hour', 3600), ('day', 86400)]
 | 
				
			||||||
        seconds = re.search(r"((\d+)\.(\d+)|(\d+))\s(second|seconds)",
 | 
					        for ts, mult in time_strings:
 | 
				
			||||||
                            duration_string)
 | 
					            total_seconds += self.get_time_unit_string(duration_string, ts, mult)
 | 
				
			||||||
        minutes = re.search(r"((\d+)\.(\d+)|(\d+))\s(minute|minutes)",
 | 
					 | 
				
			||||||
                            duration_string)
 | 
					 | 
				
			||||||
        hours = re.search(r"((\d+)\.(\d+)|(\d+))\s(hour|hours)",
 | 
					 | 
				
			||||||
                          duration_string)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if seconds is not None:
 | 
					 | 
				
			||||||
            seconds = seconds.group().strip(" seconds")
 | 
					 | 
				
			||||||
            seconds = float(seconds)
 | 
					 | 
				
			||||||
            total_seconds += seconds
 | 
					 | 
				
			||||||
        if minutes is not None:
 | 
					 | 
				
			||||||
            minutes = minutes.group().strip(" minutes")
 | 
					 | 
				
			||||||
            minutes = float(minutes)
 | 
					 | 
				
			||||||
            total_seconds += minutes * 60
 | 
					 | 
				
			||||||
        if hours is not None:
 | 
					 | 
				
			||||||
            hours = hours.group().strip(" hours")
 | 
					 | 
				
			||||||
            hours = float(hours)
 | 
					 | 
				
			||||||
            total_seconds += hours * 3600
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return total_seconds
 | 
					        return total_seconds
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @staticmethod
 | 
				
			||||||
 | 
					    def get_time_unit_string(text: str, time_text: str, multiplier: int = 1):
 | 
				
			||||||
 | 
					        substring = re.search(rf"((\d+)\.(\d+)|(\d+))\s({time_text}|{time_text}s)", text)
 | 
				
			||||||
 | 
					        if substring is not None:
 | 
				
			||||||
 | 
					            substring = substring.group().strip(f" {time_text}s")
 | 
				
			||||||
 | 
					            return float(substring) * multiplier
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def get_datetime(datetime_string):
 | 
					    def get_datetime(datetime_string):
 | 
				
			||||||
        date_string = re.search(r"....-..-..", datetime_string).group()
 | 
					        date_string = re.search(r"....-..-..", datetime_string).group()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user