def driver_get_revenue(request): access_token = AccessToken.objects.get( token=request.GET.get("access_token"), expires__gt=timezone.now()) driver = access_token.user.driver from datatime import timedelta revenue = {} today = timezone.now() current_weekdays = [ today + timedelta(days=i) for i in range(0 - today.weekday(), 7 - today.weekday()) ] for day in current_weekdays: orders = Order.objects.filter(driver=driver, status=ORder.DELIVERED, created_at__year=day.year, created_at__month=day.month, created_at__day=day.day) revenue[day.strtime("%a")] = sum(order.total for order in orders) return JsonResponse({"revenue": revenue})
def business_get_expenditure(request): access_token = AccessToken.objects.get( token=request.GET.get("access_token"), expires__gt=timezone.now()) business = access_token.user.business from datatime import timedelta revenue = {} today = timezone.now() current_weekdays = [ today + timedelta(days=i) for i in range(0 - today.weekday(), 7 - today.weekday()) ] for day in current_weekdays: orders = BusinessOrder.objects.filter(business=business, status=OrderStatus.DELIVERED, date_created__year=day.year, date_created__month=day.month, date_created__day=day.day) expenditure[day.strtime("%a")] = sum(order.total for order in orders) return JsonResponse({"expenditure": expenditure})
def precipitation(): prev_yr = dt.date(2017, 8, 23) - dt.timedelta(days=365) precipitation= session.query(Measurement.date, Measurement.prcp).\ filter(Measurement.date >= prev_yr).all() precip = {date: prcp for date, prcp in precipitation} return jsonify(precip)
def worker(row_data): logging.debug("row: %s", row_data) thread_db = database_base.MM_Server_Database() thread_db.MM_Server_Database_Open(Config.get('DB Connections', 'PostDBHost').strip(), Config.get('DB Connections', 'PostDBPort').strip(), Config.get('DB Connections', 'PostDBName').strip(), Config.get('DB Connections', 'PostDBUser').strip(), Config.get('DB Connections', 'PostDBPass').strip()) # row_data # 0 mm_sync_guid uuid NOT NULL, 1 mm_sync_path text, 2 mm_sync_path_to text, 3 mm_sync_options_json jsonb ffmpeg_params = ['ffmpeg', '-i', thread_db.MM_Server_Database_Media_Path_By_UUID(row_data[3]['Media GUID'])[0].encode('utf8')] if row_data[3]['Options']['Size'] != "Clone": ffmpeg_params.extend(('-fs', row_data[3]['Size'].encode('utf8'))) if row_data[3]['Options']['VCodec'] != "Copy": ffmpeg_params.extend(('-vcodec', row_data[3]['VCodec'])) if row_data[3]['Options']['AudioChannels'] != "Copy": ffmpeg_params.extend(('-ac', row_data[3]['Options']['AudioChannels'].encode('utf8'))) if row_data[3]['Options']['ACodec'] != "Copy": ffmpeg_params.extend(('-acodec', row_data[3]['Options']['ACodec'].encode('utf8'))) if row_data[3]['Options']['ASRate'] != 'Default': ffmpeg_params.extend(('-ar', row_data[3]['Options']['ASRate'])) ffmpeg_params.append(row_data[2].encode('utf8') + "." + row_data[3]['Options']['VContainer']) logging.debug("ffmpeg: %s", ffmpeg_params) ffmpeg_pid = subprocess.Popen(ffmpeg_params, shell=False, stdout=subprocess.PIPE) # output after it gets started # Duration: 01:31:10.10, start: 0.000000, bitrate: 4647 kb/s # frame= 1091 fps= 78 q=-1.0 Lsize= 3199kB time=00:00:36.48 bitrate= 718.4kbits/s dup=197 drop=0 speed= 2.6x media_duration = None while True: line = proc.stdout.readline() if line != '': logging.debug("ffmpeg out: %", line.rstrip()) if line.find("Duration:") != -1: media_duration = timedelta(line.split(': ', 1)[1].split(',', 1)[0]) elif line[0:5] == "frame": time_string = timedelta(line.split('=', 5)[5].split(' ', 1)[0]) time_percent = time_string.total_seconds() / media_duration.total_seconds() thread_db.MM_Server_Database_Sync_Progress_Update(row_data[0], time_percent) thread_db.MM_Server_Database_Commit() else: break ffmpeg_pid.wait() thread_db.MM_Server_Database_Activity_Insert(u'Meta-Man Server Sync', None, u'System: Server Sync', u'ServerSync', None, None, u'System') thread_db.MM_Server_Database_Sync_Delete(row_data[0]) # guid of sync record #thread_db.store record in activity table thread_db.MM_Server_Database_Commit() thread_db.MM_Server_Database_Close() return
def create_access_token(*, data: dict, expires_delta: timedelta = None): to_encode = data.copy() if expires_delta: expire = datatime.utcnow() + expires_delta else: expire = datatime.utcnow() + timedelta(15) to_encode.update({'exp': expire}) encode_jwt = jwt.encode(to_encode, config.SECRET_KEY, algorithm=ALGORITHM) return encode_jwt
def temp_monthly(): prev_yr = dt.date(2017, 8, 23) - dt.timedelta(days=365) results= session.query(Measurement.tobs).\ filter(Measurement.station == 'USC00519281').\ filter(Measurement.date >= prev_yr).all() tenps = list(np.ravel(results)) return jsonify(tenps)
from datatime import datatime, timedelta dt1 = datatime(2018, 1, 1) + timedelta(days=1, seconds=1) print(dt1) dt2 = datatime.now() duration = dt2 - dt1 print(duration) print("days", duration.days) print("seconds", duration.seconds) print("total_seconds", duration.total_seconds()) # data time objects, these objects represent a point in time. In datatime module also class called time delta, which represents a duration. # why youre wondering why we don't have month or year here, the reason is that we can have a varying amount of time in a montha or in year,That's why only days, seconds and microseconds.
data=f"{month}/{day}/20" df=confirmed_cases.groupby(by=["Country/Region"]).sum() df = df.reset_index() return df[["Country/Region", data]].sort_values(by=data, ascending=False).head(5)["Country/Region"].to_list() def no_new_cases_count(day: int, month: int, year: int = 2020) -> int: """ Returns the number of countries/regions where the infection count in a given day was the same as the previous day. Ex. >>> no_new_cases_count(11, 2, 2020) 35 >>> no_new_cases_count(3, 3) 57 :param day: 4 digit integer representation of the year to get the cases for, defaults to 2020 :param month: Day of month to get the countries for as an integer indexed from 1 :param year: Month to get the countries for as an integer indexed from 1 :return: Number of countries/regions where the count has not changed in a day """ # Your code goes here (remove pass) import datatime data_dzis=datetime.date(year,month,day) data_wczoraj=data_dzis+datatime.timedelta(days=-1) str_date = date.strftime('%m/%d/%y').lstrip('0').replace("/0", "/") str_prev_date = prev_date.strftime('%m/%d/%y').lstrip('0').replace("/0", "/") result = confirmed_cases.loc[confirmed_cases[str_date] != confirmed_cases[str_prev_date]] return result.shape[0]
>>> import datatime >>> str(datatime.timedelta(second=666)) '0:11:06'