How to use log_added method in Slash

Best Python code snippet using slash

views.py

Source:views.py Github

copy

Full Screen

1from django.http import HttpResponse2from django.shortcuts import render3from django.template import loader4import numpy as np5import matplotlib6matplotlib.use('Agg')7import matplotlib.pyplot as pl8import io, base649from django.db.models import Q10from formtools.wizard.views import SessionWizardView11from django.views.generic import TemplateView12import json13from dal import autocomplete14from .models import Category15from .models import Subcategory16from .models import Product17from .models import Event18from .models import Expense19from .forms import SearchForm20from .forms import AddEventForm21from .forms import AddExpenseForm22from .forms import AddResultForm23from .forms import PlotProductForm24from .forms import PlotExpensesForm25from .forms import PlotProductBarForm26def plots(request):27 template = loader.get_template('budget/plots.html')28 context = {29 }30 return HttpResponse(template.render(context, request))31def plot_product(request):32 if request.method == 'POST':33 form = PlotProductForm(request.POST)34 if form.is_valid():35 p = request.POST['product']36 expenses = Expense.objects.filter(product=Product.objects.get(name=p))37 return plot(request, expenses)38 else:39 form = PlotProductForm()40 template = loader.get_template('budget/plot_product.html')41 context = {42 'form': form,43 }44 return HttpResponse(template.render(context, request))45def plot(request, expenses): #jak zmieniała się cena produktu46 d = {}47 for exp in expenses:48 #print(f"--{exp} | {exp.date} | {exp.price}")49 if exp.date in d.keys():50 d[exp.date].append(exp.price)51 else:52 d[exp.date] = []53 d[exp.date].append(exp.price)54 labels = sorted(list(d.keys()))55 x = np.arange(len(labels))56 sizes = []57 for lab in labels:58 sizes.append(np.mean(d[lab]))59 fig1, ax1 = pl.subplots()60 rects1 = ax1.plot(x, sizes)61 rects2 = ax1.plot(x, sizes, 'bo')62 ax1.set_xticks(x)63 ax1.set_xticklabels(labels)64 65 flike = io.BytesIO()66 fig1.savefig(flike)67 b64 = base64.b64encode(flike.getvalue()).decode()68 context = {69 'chart': b64,70 }71 72 template = loader.get_template('budget/plot.html')73 return HttpResponse(template.render(context, request))74 75def plot_product_bar(request):76 if request.method == 'POST':77 form = PlotProductBarForm(request.POST)78 if form.is_valid():79 if request.POST['choice_field'] == 'full':80 if request.POST['title']:81 r = request.POST['title']82 expenses = Expense.objects.filter(product=Product.objects.get(name=r))83 return plot2(request, expenses, r)84 if request.POST['choice_field'] == 'detail':85 if request.POST['title']:86 r = request.POST['title']87 expenses = Expense.objects.filter(product=Product.objects.get(name=r))88 return plot3(request, expenses, r)89 else:90 form = PlotProductBarForm()91 template = loader.get_template('budget/plot_product_bar.html')92 context = {93 'form': form,94 }95 return HttpResponse(template.render(context, request))96def plot2(request, expenses, headline): #kiedy była naprawa samochodu, koszt naprawy97 d = {}98 for exp in expenses:99 #print(f"--{exp} | {exp.date} | {exp.price}")100 if exp.date in d.keys():101 d[exp.date].append(exp.price)102 else:103 d[exp.date] = []104 d[exp.date].append(exp.price)105 labels = sorted(list(d.keys()))106 x = np.arange(len(labels))107 sizes = []108 for lab in labels:109 sizes.append(np.mean(d[lab]))110 fig1, ax1 = pl.subplots()111 width = 0.5112 rects = ax1.bar(x, sizes, width)113 ax1.set_xticks(x)114 ax1.set_xticklabels(labels)115 116 flike = io.BytesIO()117 fig1.savefig(flike)118 b64 = base64.b64encode(flike.getvalue()).decode()119 template = loader.get_template('budget/plot.html')120 context = {121 'chart': b64,122 'headline': headline,123 }124 return HttpResponse(template.render(context, request))125def plot3(request, expenses, headline): # ile razy w roku była naprawa samochodu, suma kosztów napraw126 d = {}127 for exp in expenses:128 #print(f"--{exp} | {exp.date.year} | {exp.price}")129 if exp.date.year in d.keys():130 d[exp.date.year].append(exp.price)131 else:132 d[exp.date.year] = []133 d[exp.date.year].append(exp.price)134 labels = sorted(list(d.keys()))135 x = np.arange(len(labels))136 sizes = []137 h_labels = []138 for lab in labels:139 sizes.append(np.sum(d[lab]))140 h_labels.append(len(d[lab]))141 142 fig1, ax1 = pl.subplots()143 width = 0.5144 rects = ax1.bar(x, sizes, width)145 ax1.set_xticks(x)146 ax1.set_xticklabels(labels)147 148 i = 0149 for value in rects:150 height = value.get_height()151 ax1.text(value.get_x() + value.get_width()/2.,1.002*height,'%d' % int(h_labels[i]), ha='center', va='bottom')152 i += 1153 154 flike = io.BytesIO()155 fig1.savefig(flike)156 b64 = base64.b64encode(flike.getvalue()).decode()157 template = loader.get_template('budget/plot.html')158 context = {159 'chart': b64,160 'headline': headline,161 }162 return HttpResponse(template.render(context, request))163def plot_expenses(request):164 if request.method == 'POST':165 form = PlotExpensesForm(request.POST)166 if form.is_valid():167 if request.POST['choice_field'] == 'category':168 expenses = Expense.objects.all()169 return plot4(request, expenses)170 if request.POST['choice_field'] == 'subcategory':171 if request.POST['category_title']:172 r = request.POST['category_title']173 wanted_category = r174 expenses = Expense.objects.filter(category=Category.objects.get(name=wanted_category))175 return plot5(request, expenses)176 if request.POST['choice_field'] == 'product':177 if request.POST['subcategory_title']:178 r = request.POST['subcategory_title']179 expenses = Expense.objects.filter(subcategory=Subcategory.objects.get(name=r))180 return plot6(request, expenses)181 else:182 form = PlotExpensesForm()183 template = loader.get_template('budget/plot_expenses.html')184 context = {185 'form': form,186 }187 return HttpResponse(template.render(context, request))188def plot4(request, expenses): #wykres kołowy - wydatki na kategorie189 d = {}190 for exp in expenses:191 cat = Category.objects.get(expense=exp)192 if cat.name in d.keys():193 d[cat.name].append(exp.price * exp.amount)194 else:195 d[cat.name] = []196 d[cat.name].append(exp.price * exp.amount)197 198 labels = list(d.keys())199 sizes = []200 for lab in labels:201 sizes.append(np.sum(d[lab]))202 #explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')203 fig1, ax1 = pl.subplots()204 ax1.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)#, explode=explode)205 ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.206 flike = io.BytesIO()207 fig1.savefig(flike)208 b64 = base64.b64encode(flike.getvalue()).decode()209 context = {210 'chart': b64,211 }212 213 template = loader.get_template('budget/plot.html')214 return HttpResponse(template.render(context, request))215 216def plot5(request, expenses): #wykres kołowy - wydatki w kategorii jedzenie217 d = {}218 for exp in expenses:219 prod = Product.objects.get(expense=exp)220 subcat = Subcategory.objects.get(expense=exp)221 if subcat.name in d.keys():222 d[subcat.name].append(exp.price * exp.amount)223 else:224 d[subcat.name] = []225 d[subcat.name].append(exp.price * exp.amount)226 227 labels = list(d.keys())228 sizes = []229 for lab in labels:230 sizes.append(np.sum(d[lab]))231 #explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')232 fig1, ax1 = pl.subplots()233 ax1.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)#, explode=explode)234 ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.235 flike = io.BytesIO()236 fig1.savefig(flike)237 b64 = base64.b64encode(flike.getvalue()).decode()238 context = {239 'chart': b64,240 }241 template = loader.get_template('budget/plot.html')242 return HttpResponse(template.render(context, request))243def plot6(request, expenses): #wykres kołowy - wydatki w podkategorii nabiał244 d = {}245 for exp in expenses:246 prod = Product.objects.get(expense=exp)247 if prod.name in d.keys():248 d[prod.name].append(exp.price * exp.amount)249 else:250 d[prod.name] = []251 d[prod.name].append(exp.price * exp.amount)252 253 labels = list(d.keys())254 sizes = []255 for lab in labels:256 sizes.append(np.sum(d[lab]))257 #explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')258 fig1, ax1 = pl.subplots()259 ax1.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)#, explode=explode)260 ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.261 flike = io.BytesIO()262 fig1.savefig(flike)263 b64 = base64.b64encode(flike.getvalue()).decode()264 context = {265 'chart': b64,266 }267 template = loader.get_template('budget/plot.html')268 return HttpResponse(template.render(context, request))269 270#######################################################271def index(request):272 template = loader.get_template('budget/index.html')273 context = {274 }275 return HttpResponse(template.render(context, request))276#######################################################277def auto_search(request):278 template = loader.get_template('budget/auto_search.html')279 context = {280 }281 return HttpResponse(template.render(context, request))282def search(request):283 if request.method == 'POST':284 form = SearchForm(request.POST)285 if form.is_valid():286 if request.POST['choice_field'] == 'all':287 if request.POST['title']:288 if 'exact' in request.POST:289 try:290 return product(request, request.POST['title'])291 except Product.DoesNotExist:292 try:293 return expense(request, request.POST['title'])294 except Expense.DoesNotExist:295 try:296 return event(request, request.POST['title'])297 except Event.DoesNotExist:298 products = []299 return search_results_products(request, products)300 else:301 products = Product.objects.filter(name__contains=request.POST['title'])302 expenses = Expense.objects.filter(Q(expense_id__contains=request.POST['title']) | Q(product__in=products))303 events = Event.objects.filter(Q(title__contains=request.POST['title']) | Q(expense__in=expenses))304 return search_results(request, products, expenses, events)305 if request.POST['choice_field'] == 'product':306 if request.POST['title']:307 if 'exact' in request.POST:308 try:309 return product(request, request.POST['title'])310 except Product.DoesNotExist:311 products = []312 return search_results_products(request, products)313 else:314 products = Product.objects.filter(name__contains=request.POST['title'])315 return search_results_products(request, products)316 if request.POST['choice_field'] == 'expense':317 if request.POST['title']:318 if 'exact' in request.POST:319 try:320 return expense(request, request.POST['title'])321 except Expense.DoesNotExist:322 expenses = []323 return search_results_expenses(request, expenses)324 else:325 products = Product.objects.filter(name__contains=request.POST['title'])326 expenses = Expense.objects.filter(Q(expense_id__contains=request.POST['title']) | Q(product__in=products))327 return search_results_expenses(request, expenses)328 if request.POST['choice_field'] == 'event':329 if request.POST['title']:330 if 'exact' in request.POST:331 try:332 return event(request, request.POST['title'])333 except Event.DoesNotExist:334 events = []335 return search_results_events(request, events)336 else:337 products = Product.objects.filter(name__contains=request.POST['title'])338 expenses = Expense.objects.filter(product__in=products)339 events = Event.objects.filter(Q(title__contains=request.POST['title']) | Q(expense__in=expenses))340 return search_results_events(request, events)341 else:342 form = SearchForm()343 template = loader.get_template('budget/search.html')344 return HttpResponse(template.render({'form': form}, request))345def search_results(request, products, expenses, events):346 template = loader.get_template('budget/search_results.html')347 context = {348 'products': products,349 'expenses': expenses,350 'events': events,351 }352 return HttpResponse(template.render(context, request))353def search_results_products(request, products):354 template = loader.get_template('budget/search_results_products.html')355 context = {356 'products': products,357 }358 return HttpResponse(template.render(context, request))359def search_results_expenses(request, expenses):360 template = loader.get_template('budget/search_results_expenses.html')361 context = {362 'expenses': expenses,363 }364 return HttpResponse(template.render(context, request))365def search_results_events(request, events):366 template = loader.get_template('budget/search_results_events.html')367 context = {368 'events': events,369 }370 return HttpResponse(template.render(context, request))371#######################################################372def delete(request):373 Product.objects.all().delete()374 Subcategory.objects.all().delete()375 Category.objects.all().delete()376 Expense.objects.all().delete()377 Event.objects.all().delete()378 return HttpResponse("Budget - usunięto")379 380def del_products(request):381 Product.objects.all().delete()382 return HttpResponse("Product - usunięto")383def del_subcategories(request):384 Subcategory.objects.all().delete()385 return HttpResponse("Subcategory - usunięto")386def del_categories(request):387 Category.objects.all().delete()388 return HttpResponse("Category - usunięto")389def del_expenses(request):390 Expense.objects.all().delete()391 return HttpResponse("Expense - usunięto")392def del_events(request):393 Event.objects.all().delete()394 return HttpResponse("Event - usunięto")395#######################################################396def products(request):397 products = Product.objects.all()398 template = loader.get_template('budget/products.html')399 context = {400 'products': products,401 }402 return HttpResponse(template.render(context, request))403def product(request, product):404 product = Product.objects.get(name=product)405 subcategory = Subcategory.objects.get(product=product)406 category = Category.objects.get(subcategory=subcategory)407 template = loader.get_template('budget/product.html')408 context = {409 'product': product,410 'subcategory': subcategory,411 'category': category,412 }413 return HttpResponse(template.render(context, request))414def subcategories(request):415 subcategories = Subcategory.objects.all()416 template = loader.get_template('budget/subcategories.html')417 context = {418 'subcategories': subcategories,419 }420 return HttpResponse(template.render(context, request))421def subcategory(request, subcategory):422 subcategory = Subcategory.objects.get(name=subcategory)423 category = Category.objects.get(subcategory=subcategory)424 product_list = Product.objects.filter(subcategory=subcategory)425 template = loader.get_template('budget/subcategory.html')426 context = {427 'subcategory': subcategory,428 'category': category,429 'product_list': product_list,430 }431 return HttpResponse(template.render(context, request))432def categories(request):433 categories = Category.objects.all()434 template = loader.get_template('budget/categories.html')435 context = {436 'categories': categories,437 }438 return HttpResponse(template.render(context, request))439def category(request, category):440 category = Category.objects.get(name=category)441 subcategory_list = Subcategory.objects.filter(category=category)442 template = loader.get_template('budget/category.html')443 context = {444 'subcategory_list': subcategory_list,445 'category': category,446 }447 return HttpResponse(template.render(context, request))448def expenses(request):449 expenses = Expense.objects.all()450 template = loader.get_template('budget/expenses.html')451 context = {452 'expenses': expenses,453 }454 return HttpResponse(template.render(context, request))455def expense(request, expense):456 expense = Expense.objects.get(expense_id=expense)457 product = Product.objects.get(expense=expense)458 template = loader.get_template('budget/expense.html')459 context = {460 'expense': expense,461 'product': product,462 }463 return HttpResponse(template.render(context, request))464def events(request):465 events = Event.objects.all()466 template = loader.get_template('budget/events.html')467 context = {468 'events': events,469 }470 return HttpResponse(template.render(context, request))471def event(request, event):472 event = Event.objects.get(title=event)473 expense_list = Expense.objects.filter(event=event)474 template = loader.get_template('budget/event.html')475 context = {476 'event': event,477 'expense_list': expense_list,478 }479 return HttpResponse(template.render(context, request))480#######################################################481class FormWizardView(SessionWizardView):482 template_name = "budget/add_event.html"483 form_list = [AddEventForm, AddExpenseForm]#, AddResultForm]484 def get_form(self, step=None, data=None, files=None):485 form = super().get_form(step, data, files)486 487 # determine the step if not given488 if step is None:489 step = self.steps.current490 if step == '0':491 # pobrać produkty492 products = Product.objects.all()493 prod_list = [p.name for p in products]494 #print(prod_list)495 #form.fields["product"].initial = "chleb"496 #print(form.fields["product"])497 return form498 499 def get_context_data(self, **kwargs):500 data = super().get_context_data(**kwargs)501 products = Product.objects.all()502 prod_list = [p.name for p in products]503 data['prod_list'] = prod_list504 categories = Category.objects.all()505 cat_list = [c.name for c in categories]506 data['cat_list'] = cat_list507 subcategories = Subcategory.objects.all()508 subcat_list = [s.name for s in subcategories]509 data['subcat_list'] = subcat_list510 return data511 512 def done(self, form_list, **kwargs):513 cleaned_data = self.get_all_cleaned_data()514 title = cleaned_data['title']515 date = cleaned_data['date']516 price = cleaned_data['price']517 amount = cleaned_data['amount']518 product = cleaned_data['product']519 product_to_add = Product.objects.get(name=product)520 subcategory = cleaned_data['subcategory']521 subcategory_to_add = Subcategory.objects.get(name=subcategory)522 category = cleaned_data['category']523 category_to_add = Category.objects.get(name=category)524 q = Event.objects.filter(title=cleaned_data['title'])525 if len(q) == 0:526 e = Event(title=cleaned_data['title'])527 e.save()528 expenses = list(Expense.objects.all())529 ex_id = int(expenses[-1].expense_id) + 1530 ex = Expense(expense_id=ex_id, date=cleaned_data['date'], price=cleaned_data['price'], amount=cleaned_data['amount'], product=product_to_add, subcategory=subcategory_to_add, category=category_to_add)531 ex.save()532 e = Event.objects.get(title=cleaned_data['title'])533 e.expense.add(ex)534 e.save()535 context = {536 'form_data': cleaned_data,537 'title': cleaned_data['title'],538 'date': date,539 'price': price,540 'amount': amount,541 'product': product,542 'subcategory': subcategory,543 'category': category,544 }545 return render(self.request, 'budget/done.html', context)546'''547def add_event(request):548 if request.method == 'POST':549 form = AddEventForm(request.POST)550 if form.is_valid():551 q = Event.objects.filter(title=request.POST['title'])552 if len(q) == 0:553 e = Event(title=request.POST['title'])554 e.save()555 # expenses = list(Expense.objects.all())556 # p =Product.objects.get(name=request.POST['expense_product'])557 # ex_id = int(expenses[-1].expense_id) + 1558 # ex = Expense(expense_id=ex_id, date=request.POST['expense_date'], price=request.POST['expense_price'], amount=request.POST['expense_amount'], product=p, subcategory=request.POST['expense_subcategory'], category=request.POST['expense_category'])559 # ex.save()560 # return add_expense(request, request.POST['title'])561 # return add_result(request, request.POST['title'])562 else:563 form = AddEventForm()564 template = loader.get_template('budget/add_event.html')565 context = {566 'form': form,567 }568 return HttpResponse(template.render(context, request))569 570def add_expense(request, event_title):571 if request.method == 'POST':572 e = Event.objects.get(title=event_title)573 form = AddExpenseForm(request.POST)574 if form.is_valid():575 p = Product.objects.get(name=request.POST['expense_product'])576 # ex_id = int(expenses[-1].expense_id) + 1577 # ex = Expense(expense_id=ex_id, date=request.POST['expense_date'], price=request.POST['expense_price'], amount=request.POST['expense_amount'], product=p, subcategory=request.POST['expense_subcategory'], category=request.POST['expense_category'])578 # ex.save()579 # print('---',event_title)580 print('---', p)581 return add_result(request, event_title)582 else:583 print('--- form not valid')584 else:585 form = AddExpenseForm()586 print('--- else')587 template = loader.get_template('budget/add_event.html')588 context = {589 'form': form,590 }591 return HttpResponse(template.render(context, request))592'''593def add_result(request, title):594 template = loader.get_template('budget/add_result.html')595 context = {596 'title': title,597 }598 return HttpResponse(template.render(context, request))599def import_products(request):600 products = np.loadtxt('products.txt', delimiter=',', dtype='str')601 log_added = ""602 log_excepted = ""603 for product in products:604 new_name = product[0]605 q = Product.objects.filter(name=new_name)606 if len(q) == 0:607 p = Product(name=new_name)608 p.save()609 log_added += new_name + "<br>"610 else:611 log_excepted = new_name + "<br>"612 return HttpResponse("Pominięto:<br> %s<br>Dodano:<br>%s" % (log_excepted,log_added))613def import_subcategories(request):614 subcategories = np.loadtxt('subcategories.txt', delimiter=',', dtype='str')615 products = np.loadtxt('products.txt', delimiter=',', dtype='str')616 log_added = ""617 log_excepted = ""618 for subcategory in subcategories:619 new_name = subcategory[0]620 q = Subcategory.objects.filter(name=new_name)621 if len(q) == 0:622 s = Subcategory(name=new_name)623 s.save()624 for product in products:625 pr_name = product[0]626 pr_subcategory = product[1]627 if pr_subcategory == new_name:628 p = Product.objects.get(name=pr_name)629 s.product.add(p)630 s.save()631 log_added += new_name + "<br>"632 else:633 log_excepted = new_name + "<br>"634 return HttpResponse("Pominięto:<br> %s<br>Dodano:<br>%s" % (log_excepted,log_added))635def import_categories(request):636 categories = np.loadtxt('categories.txt', delimiter=',', dtype='str')637 subcategories = np.loadtxt('subcategories.txt', delimiter=',', dtype='str')638 log_added = ""639 log_excepted = ""640 for category in categories:641 new_name = category642 q = Category.objects.filter(name=new_name)643 if len(q) == 0:644 c = Category(name=new_name)645 c.save()646 for subcategory in subcategories:647 s_name = subcategory[0]648 s_category = subcategory[1]649 if s_category == new_name:650 s = Subcategory.objects.get(name=s_name)651 c.subcategory.add(s)652 c.save()653 log_added += new_name + "<br>"654 else:655 log_excepted = new_name + "<br>"656 return HttpResponse("Pominięto:<br> %s<br>Dodano:<br>%s" % (log_excepted,log_added))657def import_expenses(request):658 expenses = np.loadtxt('expenses.txt', delimiter=',', dtype='str')659 products = np.loadtxt('products.txt', delimiter=',', dtype='str')660 log_added = ""661 log_excepted = ""662 for expense in expenses:663 new_id = expense[0]664 new_date = expense[2]665 new_price = expense[3]666 new_amount = expense[4]667 new_product = expense[5]668 q = Expense.objects.filter(expense_id=new_id)669 if len(q) == 0:670 p = Product.objects.get(name=new_product)671 sc = Subcategory.objects.get(product=p)672 c = Category.objects.get(subcategory=sc)673 e = Expense(expense_id=new_id, date=new_date, price=new_price, amount=new_amount, product=p, subcategory=sc, category=c)674 e.save()675 log_added += new_id + "<br>"676 else:677 log_excepted = new_id + "<br>"678 return HttpResponse("Pominięto:<br> %s<br>Dodano:<br>%s" % (log_excepted,log_added))679def import_events(request):680 events = np.loadtxt('events.txt', delimiter=',', dtype='str')681 expenses = np.loadtxt('expenses.txt', delimiter=',', dtype='str')682 log_added = ""683 log_excepted = ""684 for event in events:685 new_title = event686 q = Event.objects.filter(title=new_title)687 if len(q) == 0:688 e = Event(title=new_title)689 e.save()690 for expense in expenses:691 ex_id = expense[0]692 ex_title = expense[1]693 if ex_title == new_title:694 ex = Expense.objects.get(expense_id=ex_id)695 e.expense.add(ex)696 e.save()697 log_added += new_title + "<br>"698 else:699 log_excepted = new_title + "<br>"700 return HttpResponse("Pominięto:<br> %s<br>Dodano:<br>%s" % (log_excepted,log_added))701def import_all(request):702 products = add_products(request)703 subcategories = add_subcategories(request)704 categories = add_categories(request)705 expenses = add_expenses(request)706 events = add_events(request)...

Full Screen

Full Screen

simple.py

Source:simple.py Github

copy

Full Screen

1# This file is part of the Cachegrab GUI.2#3# Copyright (C) 2017 NCC Group4#5# This program is free software; you can redistribute it and/or6# modify it under the terms of the GNU General Public License7# as published by the Free Software Foundation; either version 28# of the License, or (at your option) any later version.9#10# This program is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13# GNU General Public License for more details.14#15# You should have received a copy of the GNU General Public License16# along with Cachegrab. If not, see <http://www.gnu.org/licenses/>.17# Version 0.1.018# Keegan Ryan, NCC Group19import wx20from pubsub import pub21from cachegrab.sinks import AnalysisSink22class AnalysisSimpleGui(wx.Panel):23 """View corresponding to AnalysisSimple sink"""24 def __init__(self, parent, simple_sink):25 """Set up GUI and load in data"""26 wx.Panel.__init__(self, parent, wx.ID_ANY)27 # Initialize controller28 self.simple = simple_sink29 # Initialize view30 sizer = wx.BoxSizer(wx.VERTICAL)31 self.log = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_MULTILINE)32 sizer.Add(self.log, 1, wx.EXPAND)33 sizer.SetSizeHints(self)34 self.SetSizer(sizer)35 # Register to pubsub events36 pub.subscribe(self.log_changed, AnalysisSimple.LOG_ADDED)37 # Fill in views38 def log_changed(self, log):39 self.log.write(log)40class AnalysisSimple(AnalysisSink):41 """Logs basic information about the collected sample."""42 typename = "Simple_Analysis"43 # Different pubsub events44 LOG_ADDED = "ANALYSIS_SIMPLE_LOG_ADDED"45 def __init__(self):46 """Initialize the sink object."""47 AnalysisSink.__init__(self)48 self.loglines = ""49 def log(self, val):50 """Write the specified value to the loglines, followed by newline."""51 with_newline = val + "\n"52 self.loglines += with_newline53 pub.sendMessage(AnalysisSimple.LOG_ADDED, log=with_newline)54 def analyze_once(self, sample):55 """Analyze a single sample."""56 trace_names = sample.get_trace_names()57 logline = "Traces: " + " ".join(trace_names)58 trace = sample.get_trace(trace_names[0]).data59 logline += " shape: " + str(trace.shape)60 self.log(logline)61 def get_log(self):62 """Return the log text"""...

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 Slash 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