def post(self): try: # get input data as json and read required fields some_json = request.get_json() lat = to_float(some_json['lat'], 'lat') long = to_float(some_json['long'], 'long') epoch = to_float(some_json['epoch'], 'epoch') orientation = to_float(some_json['orientation'], 'orientation') if (lat < 0 or lat > 90): raise ValueError("ValueError: lat out of range = [0 to 90]") elif (long < -180 or long > 180): raise ValueError( "ValueError: long out of range = [-180 to 180") elif (orientation < -180 or orientation > 180): raise ValueError( "ValueError: orientation out of range = [-180 to 180]") elif (epoch < 0): raise ValueError( "ValueError: epoch out of range = [epoch > 0]") else: # create objects tz_utils = TimeZoneUtils() date_utils = DateUtils(tz_utils) coord_utils = CoordinationUtils(date_utils, lat, long, epoch, orientation) # compute glare and return results return ({'glare': coord_utils.detect_glare()}) except Exception as e: print(e) return ({'Error': str(e)})
def main(): date_str = "2021-06-03 16:46:00" du = DateUtils() result = du.str_to_date(date_str) print(result, type(result)) # out: 2021-06-03 16:46:00 <class 'datetime.datetime'>
def print(self): dateutil_obj = DateUtils() for cpu_time in self.cpu_times_proto.cpu_times: print("CPU Index: {}".format(cpu_time.cpu_index)) print("统计时间: {}".format( dateutil_obj.timestamp_to_string(cpu_time.timestamp))) print("用户进程耗时: {}(秒)".format(cpu_time.user_mode_time)) print("内核进程耗时: {}(秒)".format(cpu_time.kernel_mode_time)) print("CPU空闲时间: {}(秒)".format(cpu_time.idle_time))
def parse_log(self): binning_index = {} for FILE in self.files: for line in open (FILE): if re.match (r'^#', line): continue ts = line.split (self.field_seperator)[self.ts_col] try: current_index = self.dataset + '-' + DateUtils (ts, self.timeformat).get_binning_index () except: current_index = '' if current_index: if current_index not in binning_index: binning_index[current_index] = 1 else: binning_index[current_index] = binning_index[current_index] + 1 return binning_index