Skip to content

Instantly share code, notes, and snippets.

@idrummer83
Created July 15, 2020 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idrummer83/74310df8750cc3acfc64a63c4caf02ec to your computer and use it in GitHub Desktop.
Save idrummer83/74310df8750cc3acfc64a63c4caf02ec to your computer and use it in GitHub Desktop.
codes
def calc_cao_sio2(osnovnost, cao_type, sio2_type):
composit = active_stack()
b_comp = base_sum_calc_components()
l = composit.last()
try:
if l.name == 'Известь' or l == 'Известь':
a = sum([i.weight for i in composit[:len(composit) - 1]])
# else:
# a = sum([i.weight for i in composit])
except AttributeError:
pass
else:
a = sum([i.weight for i in composit])
if b_comp['soft_weight_sum'] > 0:
if cao_type == 'dry':
element_cao_sum_dry = sum(
[(i.element_cao * (i.weight * (1 - i.element_w / 100)) / 100) for i in composit])
cao = round(element_cao_sum_dry, 3)
else:
element_cao_sum_wet = sum([(i.element_cao * i.weight / 100) for i in composit])
cao = round(element_cao_sum_wet, 3)
if sio2_type == 'dry':
element_sio2_sum_dry = sum([(i.element_sio2 * (i.weight*(1-i.element_w/100)) / 100) for i in composit])
sio2 = round(element_sio2_sum_dry, 3)
else:
element_sio2_sum_wet = sum([(i.element_sio2 * i.weight / 100) for i in composit])
sio2 = round(element_sio2_sum_wet, 3)
x_val_dry = 0
x_val_wet = 0
ch = Receipt.objects.filter(name='Известь').first()
if ch is not True:
chalk = 82.0
else:
chalk = ch.element_cao
if cao_type == 'dry':
x_val_dry = float(osnovnost) * sio2 - cao
need_weight_val = round(x_val_dry / (chalk / 100), 3)
consumptionLime = round((need_weight_val / a) * 1000, 3)
else:
x_val_wet = float(osnovnost) * sio2 - cao
need_weight_val = round(x_val_wet / (chalk / 100), 3)
consumptionLime = round((need_weight_val / a) * 1000, 3)
last = Composite.objects.all().last()
if last.name == 'Известь':
# need_weight_val = None
consumptionLime = None
st = Stack.objects.filter(active=True).first()
cxt = {
'stack_cao': st.stack_cao,
'basicity': round((cao / sio2), 3),
'x_val_dry': x_val_dry,
'x_val_wet': x_val_wet,
'need_weight_val': need_weight_val,
'consumptionLime': consumptionLime,
}
else:
cxt = {
'stack_cao': 0.9,
'basicity': 0,
'x_val_dry': None,
'x_val_wet': None,
'need_weight_val': None,
'consumptionLime': None,
}
return cxt
def inv_template_create(request, start, end, metrik, tarifs, pk):
dates_m = [
([i.indicator.id, i.value]) for i in metrik
if datetime.strptime(start, '%d-%m-%Y') < datetime.strptime(i.date.strftime('%d-%m-%Y'), '%d-%m-%Y')
and datetime.strptime(end, '%d-%m-%Y') > datetime.strptime(i.date.strftime('%d-%m-%Y'), '%d-%m-%Y')
]
snd = UserApartment.objects.filter(apparment_id__apartment=pk).first()
frst = snd.user_id.first_name or snd.user_id.username
scnd = snd.user_id.last_name or snd.user_id.username
sender = '{} {}.'.format(frst, scnd[0])
tarifs_indicator = {}
for i in range(len(tarifs)):
if tarifs[i].id == dates_m[i][0]:
res = {}
res['indicator_name'] = tarifs[i].indicator.name
res['tarif'] = tarifs[i].value
res['indicator_period'] = dates_m[i][1]
res['calc_result'] = tarifs[i].value * dates_m[i][1]
tarifs_indicator[tarifs[i].indicator.name] = res
context = {
'date_start': start,
'date_end': end,
'sender': sender,
'apartment': snd.apparment_id.apartment,
'results_cold_w': tarifs_indicator['Водопостач. та водовідведення'],
'results_hot_w': tarifs_indicator['Вода гаряча та водовідведення'],
'electricity': tarifs_indicator['Енерго-постачання'],
'gabage_remove': tarifs_indicator['Вивіз сміття']
}
return render(request, 'invoice_template.html', context)
def invoicegenerate(request, pk):
if request.method == 'POST':
start = request.POST['start']
end = request.POST['end']
metrik = ApartmentMetric.objects.filter(apartment_id=pk)
tarifs = IndicatorTarif.objects.all()
invoice_parse = inv_template_create(request, start, end, metrik, tarifs, pk)
Invoice.objects.create(
apartment=Apartment.objects.filter(id=1).first(), generated_by=UserProfil.objects.filter(id=1).first(),
date=datetime.now(), invoice=invoice_parse.content.decode()).save()
return render(request, 'invoice_result.html', {'invoice_parse': invoice_parse.content.decode()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment