This commit is contained in:
2022-02-14 18:38:00 +01:00
parent 4bfe868a6c
commit 2e72350a36
2 changed files with 70 additions and 45 deletions

View File

@@ -3,7 +3,7 @@ from datetime import datetime
import sys import sys
import pandas as pd import pandas as pd
FILE = 'TMGDSP202105.CSV' FILE = 'TMGDSP202110.CSV'
#usrmonth = input("Month to be processed: ") #usrmonth = input("Month to be processed: ")
@@ -70,10 +70,12 @@ with open(FILE, newline='', encoding='utf-8') as csvfile:
MSISDN = int(row['MSISDN']) MSISDN = int(row['MSISDN'])
ICCID = int(row['ICCID']) ICCID = int(row['ICCID'])
price1 = float(row['CHARGE_NET'].replace(',','.'))
print("charge_net: ",row['CHARGE_NET'])
price = round(price1, 5) price = float(row['CHARGE_NET'].replace(',','.'))
print("before conditions price: ",price) price = round(price, 5)
print("before conditions price: ",price, "for: ",ICCID)
typ = None typ = None
if row['CHARGE_TYPE'] == "Pravidelné měsíční poplatky": if row['CHARGE_TYPE'] == "Pravidelné měsíční poplatky":
@@ -102,12 +104,12 @@ with open(FILE, newline='', encoding='utf-8') as csvfile:
dictionary[MSISDN] = {'ICCID':ICCID,'data':0.00000, 'sms':0.00000, 'other':0.00000, 'smscount':pricesms} dictionary[MSISDN] = {'ICCID':ICCID,'data':0.00000, 'sms':0.00000, 'other':0.00000, 'smscount':pricesms}
print("Creating new dictionary: ", dictionary[MSISDN]) print("Creating new dictionary: ", dictionary[MSISDN])
else:
print("Adding: ", price, " for: ", dictionary[MSISDN], "TYP: ",typ) print("Adding: ", price, " for: ", dictionary[MSISDN], "TYP: ",typ)
add_dict(MSISDN, typ, price) add_dict(MSISDN, typ, price)
if row['INCREMENT'] == "SMS": if row['INCREMENT'] == "SMS":
print("pricesms: ",pricesms," for unit: ",dictionary[MSISDN]) print("pricesms: ",pricesms," for unit: ",dictionary[MSISDN])
add_dictsms(MSISDN, pricesms) add_dictsms(MSISDN, pricesms)
@@ -141,7 +143,7 @@ print("Count of units: ", len(dictionary.keys()))
csv_columns = ['takhleuztoneudelam', 'ICCID', 'data', 'sms', 'other', 'smscount'] csv_columns = ['takhleuztoneudelam', 'ICCID', 'data', 'sms', 'other', 'smscount']
try: try:
with open('fakturace_tmgdsp_export_20211110v3.csv', 'w') as csvfile: with open('fakturace_tmgdsp_export_202110v1.csv', 'w') as csvfile:
w = csv.DictWriter(sys.stdout, csv_columns) w = csv.DictWriter(sys.stdout, csv_columns)
for key, val in sorted(dictionary.items()): for key, val in sorted(dictionary.items()):
row = {'takhleuztoneudelam': key} row = {'takhleuztoneudelam': key}
@@ -151,4 +153,4 @@ try:
writer.writerow(row) writer.writerow(row)
except IOError: except IOError:
print(f"I/O error: {IOError}") print(f"I/O error: {IOError}")

View File

@@ -35,16 +35,14 @@ def add_dict2(ICCID, IMSI):
dict['IMSI'] = IMSI dict['IMSI'] = IMSI
print('updated', dict) print('updated', dict)
def add_dictsms(id, key, value): def add_dictsms(id, pricesms):
dict = dictionary.get(id) dict = dictionary.get(id)
value_ = float(value)
if key in dict: print("increasing sms dict key for dict: ",dict," for :",pricesms)
dict[key] == value_ dict["smscount"] += pricesms
else:
print("Never should happen", id)
def add_dictsmsprice(ICCID3, pricesms): def add_dictsmsprice(ICCID3, pricesms):
dict2 = dictionary.get(ICCID3) dict2 = dictionary.get(ICCID2)
print("section 3, add to sms") print("section 3, add to sms")
print(dict2) print(dict2)
print("increasing sms dict key for dict: ",dict2 , " for :", pricesms) print("increasing sms dict key for dict: ",dict2 , " for :", pricesms)
@@ -96,7 +94,7 @@ with open(FILE, newline='', encoding="utf-8") as csvfile:
print("Creating dictionary: ", ICCID) print("Creating dictionary: ", ICCID)
dictionary[ICCID] = {'IMSI': 0,'data': price, 'sms': 0.00000, 'other': 0.00000, 'smscount': 0} dictionary[ICCID] = {'IMSI': 0,'data': price, 'sms': 0.00000, 'other': 0.00000, 'smscount': 0}
xxx = []
print("Start section 2") print("Start section 2")
with open(FILE2, newline='', encoding="utf-8") as csvfile2: with open(FILE2, newline='', encoding="utf-8") as csvfile2:
reader2 = csv.DictReader(csvfile2, delimiter=',') reader2 = csv.DictReader(csvfile2, delimiter=',')
@@ -105,36 +103,61 @@ with open(FILE2, newline='', encoding="utf-8") as csvfile2:
IMSI = int(row['IMSI']) IMSI = int(row['IMSI'])
ICCID2 = ICCID3 = int(row['ICCID']) ICCID2 = ICCID3 = int(row['ICCID'])
ICCID3 = int(ICCID2) ICCID3 = int(ICCID2)
print("Je to jeste ok? ",ICCID3)
xxx.append(int(row['ICCID']))
if ICCID2 in dictionary: if ICCID2 in dictionary:
print("Adding IMSI: ",IMSI ,"to dictionary: ", ICCID2) print("Adding IMSI: ",IMSI ,"to dictionary: ", ICCID2)
add_dict2(ICCID2, IMSI) add_dict2(ICCID2, IMSI)
print("sec2 end")
print("Start section 3")
i = 0
x = 0
with open(FILE3, newline='', encoding="utf-8") as csvfile3:
reader3 = csv.DictReader(csvfile3, delimiter=',')
for row in reader3:
smspay = int(row['Nr. of SMS payload'])
smsmo = int(row['Nr. of SMS MO'])
imsi = int(row['IMSI'])
print("IMSI: ",imsi)
print("smspay: ",smspay)
print("smsmo: ", smsmo)
price = smspay * smsmo * 1.28
for key,value in dictionary.items():
print(key, value)
print("iterations: ", x)
print("succesfuly paired: ", i)
x += 1
if type(value) is dict:
for key, val in value.items():
# print("Start section 3") #print(key,"→", val)
# with open(FILE3, newline='', encoding="utf-8") as csvfile3: if val == imsi:
# reader3 = csv.DictReader(csvfile3, delimiter=',') print("succesfuly paired: ", i)
# for row in reader3: i += 1
# print(xxx[1]) print("got it, IMSI: ", imsi," is paired to ICCID:", ICCID2)
# print("we got bad ICCIDfinal from section 2! :",xxx[5]) #add_dictsms(ICCID2, pricesms)
# IMSI2 = int(row['IMSI']) print(dictionary[ICCID2])
# print(row['Nr. of SMS payload']) #sys.exit()
# print(row['Nr. of SMS MO'])
# smspay = int(row['Nr. of SMS payload']) # just get the dictionary key by matching IMSI
# smsmo = int(row['Nr. of SMS MO']) #dictionary = {'george': 16, 'amber': 19}
#
#
# price = smspay * smsmo * 1.28
#
#
# print("Dict: ", dict) #sys.exit()
# for x in xxx:
#
# print("Adding SMSprice: ",price ,"to dictionary: ", x)
#
# add_dictsmsprice(x, price) #print("Adding SMSprice: ",price ,"to dictionary: ", x)
#add_dictsmsprice(x, price)