How to use name_for_file method in avocado

Best Python code snippet using avocado_python

get_features_for_pn_py37.py

Source:get_features_for_pn_py37.py Github

copy

Full Screen

1def get_features_for_pn_py37():2 import re3 import warnings4 import numpy as np5 from tqdm import tqdm6 from src.readers import Writer, Reader7 warnings.filterwarnings("ignore")8 app_name = "test_app"9 processor_backend_name = "py37ds"10 reader = Reader(app_name, processor_backend_name)11 """12 Этот скрипт формирует признаки и таргеты из выдачи на борт. 13 Фичи по PN : 14 - последняя выдача , сколько дней назад;15 - кол-во выдачи в последний раз; 16 - сумма по всем выдачам; 17 Таргеты по PN: 18 - выдача данного PN на данный визит; 19 """20 df_visits = reader.read_by_draft_name("normalized_visits")21 df_visits = df_visits[['VISIT_ID', 'INSTANCE_ID', 'ACTUAL_START_DATE']].drop_duplicates().copy()22 df_visits['ACTUAL_START_DATE'] = df_visits.ACTUAL_START_DATE.apply(lambda x: np.datetime64(x))23 """ загружаем результаты 1_get..... """24 df_PN = reader.read_by_draft_name("pn_purchase_visit_id_dict")25 df_PN['TRANSACTION_DATE'] = df_PN.TRANSACTION_DATE.apply(lambda x: np.datetime64(x))26 df_PN_dict = reader.read_by_draft_name("pn_dict")27 def get_days_before(AC, date, VISIT_ID, df_find):28 """29 Выдает:30 -выдачу в это визит;31 -прошлую выдачу этого PN;32 -кол-во дней с прошлой выдачи этого PN;33 -обратную сумму всех прошлых выдачей;34 """35 this_visit_qti = df_find[df_find.VISIT_ID == VISIT_ID]["REAL_TRANSACTION_QUANTITY_FLOAT_NEW"].sum()36 # Учтем , что могли выдать заранее37 df_temp = df_find[(df_find.INSTANCE_ID == AC) &38 (df_find.TRANSACTION_DATE < (date - np.timedelta64(7, 'D')))].copy()39 if len(df_temp) > 0:40 df_temp['delta'] = abs(df_temp['TRANSACTION_DATE'] - date) / np.timedelta64(1, 'D')41 df_temp.sort_values('delta', inplace=True)42 last_qti = df_temp["REAL_TRANSACTION_QUANTITY_FLOAT_NEW"].values[0]43 min_days_ago = round(df_temp['delta'].min(), 1)44 # сумма по всем выдачам45 df_temp['delta'] = df_temp['REAL_TRANSACTION_QUANTITY_FLOAT_NEW'] / df_temp['delta']46 return this_visit_qti, last_qti, min_days_ago, round(df_temp['delta'].sum(), 4)47 return this_visit_qti, None, None, None48 writer = Writer(app_name, processor_backend_name)49 for item_name, item_desc, uom, name_for_file in tqdm(df_PN_dict[:2].values):50 if re.sub('[^A-Z0-9]', '', name_for_file) == '':51 continue52 df_PN_temp = df_PN[(df_PN.ITEM_NAME == item_name) &53 (df_PN.ITEM_DESCRIPTION == item_desc) &54 (df_PN.UOM_NAME == uom)].copy()55 df_visits['temp'] = df_visits.apply(lambda row:56 get_days_before(row['INSTANCE_ID'],57 row['ACTUAL_START_DATE'],58 row['VISIT_ID'],59 df_find=df_PN_temp), axis=1)60 df_visits['TARGET'] = df_visits.temp.apply(lambda x: x[0])61 df_visits[name_for_file + '_last_qti'] = df_visits.temp.apply(lambda x: x[1])62 df_visits[name_for_file + '_days_ago'] = df_visits.temp.apply(lambda x: x[2])63 df_visits[name_for_file + '_sum_qti_vs_days'] = df_visits.temp.apply(lambda x: x[3])64 df_visits.drop('temp', axis=1, inplace=True)65 writer.write_by_draft_name_single_sink(df_visits.drop('ACTUAL_START_DATE', axis=1), name_for_file.upper())...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

1from django.test import TestCase2from unittest import mock3from django.shortcuts import resolve_url4import datetime as dt5import os6from . import views, models7from .actions import graph_helper8from dotenv import load_dotenv9load_dotenv()10# Create your tests here.11class Daily_reportTest(TestCase):12 def test_get_time(self):13 os.environ['TZ'] = 'Asia/Tokyo'14 to_day, now = views.get_time()15 os.environ['TZ'] = 'us'16 to_day2, now2 = views.get_time()17 now = now.isoformat(timespec='minutes')18 now2 = now2 + dt.timedelta(hours=9) # 9時間差19 now2 = now2.isoformat(timespec='minutes')20 self.assertEqual(now, now2)21 def mock_initialize_context(self):22 return {'user': {'email': os.environ['MS_ID']}}23 @mock.patch('daily_report.views.initialize_context', mock_initialize_context)24 def test_home(self):25 res = self.client.get(resolve_url('daily_report:home'))26 self.assertEqual(200, res.status_code)27 self.assertTrue(res.context.get('store_name'))28 def test_select_filename(self):29 name_for_file = 'FES'30 store_name = 'fes'31 to_day = dt.datetime(2021, 10, 9).date()32 test_name = 'テスト用'33 # DBに入ってなければ34 target_file_name = graph_helper.select_filename(name_for_file, store_name, to_day, test_name, models)35 self.assertEqual(target_file_name, f'【{name_for_file}】{to_day.year}{str(to_day.month).zfill(2)}{test_name}.xlsx')36 # 複製があれば37 models.TargetFileName.objects.filter(store='fes').update(file_name=f'【{name_for_file}】{to_day.year}{str(to_day.month).zfill(2)}{test_name}_複製1.xlsx')38 target_file_name = graph_helper.select_filename(name_for_file, store_name, to_day, test_name, models)39 self.assertEqual(target_file_name, f'【{name_for_file}】{to_day.year}{str(to_day.month).zfill(2)}{test_name}_複製1.xlsx')40 # 複製があれば241 models.TargetFileName.objects.filter(store='fes').update(file_name=f'【{name_for_file}】{to_day.year}{str(to_day.month).zfill(2)}{test_name}_複製2.xlsx')42 target_file_name = graph_helper.select_filename(name_for_file, store_name, to_day, test_name, models)43 self.assertEqual(target_file_name, f'【{name_for_file}】{to_day.year}{str(to_day.month).zfill(2)}{test_name}_複製2.xlsx')44 # 月が進んだら45 to_day = dt.datetime(2021, 11, 9).date()46 target_file_name = graph_helper.select_filename(name_for_file, store_name, to_day, test_name, models)...

Full Screen

Full Screen

locate.py

Source:locate.py Github

copy

Full Screen

1from tkinter.simpledialog import askstring2from tkinter.messagebox import askyesno3from PIL import ImageTk, Image4def folder_format(location, folder):5 return '{}/'.format(location) + '{}/'.format(folder) + '{}'6def location(count=0):7 with open('misc/location.txt', 'r', encoding='utf-8') as f:8 return f.readline().replace('\n', '')9def save(file_name, text):10 with open(DECKFLD.format(file_name), 'w', encoding='utf-8') as f:11 f.write(text)12def delete(file_name):13 if not askyesno(14 'Confirmation', f'Are you sure you want to delete {file_name}?'):15 return False # if cancel or close16 os.remove(DECKFLD.format(file_name))17 return True18def save_as(text):19 name_for_file = askstring('Save As', 'Name of Deck')20 if not name_for_file: return False # if cancel or close21 while f'{name_for_file}.txt' in os.listdir(f'{location()}/{DECKS}'):22 name_for_file += '_'23 file_name = f'{name_for_file}.txt'24 with open(DECKFLD.format(file_name), 'x', encoding='utf-8') as f:25 f.write(text)26 return True27def load_init_deck():28 with open(LOADDECK, 'r', encoding='utf-8') as f:29 return f.read()30def update_init_load(text):31 with open(LOADDECK, 'w', encoding='utf-8') as f:32 f.write(text)33def grab_deck(file_name):34 with open(DECKFLD.format(file_name), 'r', encoding='utf-8') as f:35 return f.read().split('\n')36def add_image(file_name, width, height, angle=0):37 try: img = Image.open(PICFLD.format(file_name))38 except: img = Image.open(PICFLD.format(BACKIMG))39 rotate_img = img.rotate(angle, expand=True)40 resize_img = rotate_img.resize((width, height), Image.ANTIALIAS)41 return ImageTk.PhotoImage(resize_img)42INFO = 'info'43PIC = 'pic'44DECKS = 'decks'45INFOFLD = folder_format(location(), INFO)46PICFLD = folder_format(location(), PIC)47DECKFLD = folder_format(location(), DECKS)48FORMAT = f'{location()}/format.txt'49LOADDECK = f'{location()}/load.txt'50BACKIMG = '1.png'51SHOW = 'red'...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful