Compare commits
2 Commits
4bfe868a6c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9de05150bc | |||
| 2e72350a36 |
@@ -3,7 +3,7 @@ from datetime import datetime
|
||||
import sys
|
||||
import pandas as pd
|
||||
|
||||
FILE = 'TMGDSP202105.CSV'
|
||||
FILE = 'TMGDSP202110.CSV'
|
||||
|
||||
#usrmonth = input("Month to be processed: ")
|
||||
|
||||
@@ -70,10 +70,12 @@ with open(FILE, newline='', encoding='utf-8') as csvfile:
|
||||
|
||||
MSISDN = int(row['MSISDN'])
|
||||
ICCID = int(row['ICCID'])
|
||||
price1 = float(row['CHARGE_NET'].replace(',','.'))
|
||||
|
||||
price = round(price1, 5)
|
||||
print("before conditions price: ",price)
|
||||
|
||||
print("charge_net: ",row['CHARGE_NET'])
|
||||
price = float(row['CHARGE_NET'].replace(',','.'))
|
||||
price = round(price, 5)
|
||||
|
||||
print("before conditions price: ",price, "for: ",ICCID)
|
||||
|
||||
typ = None
|
||||
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}
|
||||
print("Creating new dictionary: ", dictionary[MSISDN])
|
||||
|
||||
else:
|
||||
print("Adding: ", price, " for: ", dictionary[MSISDN], "TYP: ",typ)
|
||||
add_dict(MSISDN, typ, price)
|
||||
if row['INCREMENT'] == "SMS":
|
||||
print("pricesms: ",pricesms," for unit: ",dictionary[MSISDN])
|
||||
add_dictsms(MSISDN, pricesms)
|
||||
|
||||
print("Adding: ", price, " for: ", dictionary[MSISDN], "TYP: ",typ)
|
||||
add_dict(MSISDN, typ, price)
|
||||
if row['INCREMENT'] == "SMS":
|
||||
print("pricesms: ",pricesms," for unit: ",dictionary[MSISDN])
|
||||
add_dictsms(MSISDN, pricesms)
|
||||
|
||||
|
||||
|
||||
@@ -141,7 +143,7 @@ print("Count of units: ", len(dictionary.keys()))
|
||||
|
||||
csv_columns = ['takhleuztoneudelam', 'ICCID', 'data', 'sms', 'other', 'smscount']
|
||||
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)
|
||||
for key, val in sorted(dictionary.items()):
|
||||
row = {'takhleuztoneudelam': key}
|
||||
@@ -151,4 +153,4 @@ try:
|
||||
writer.writerow(row)
|
||||
|
||||
except IOError:
|
||||
print(f"I/O error: {IOError}")
|
||||
print(f"I/O error: {IOError}")
|
||||
87
vdgdsp.py
87
vdgdsp.py
@@ -35,16 +35,14 @@ def add_dict2(ICCID, IMSI):
|
||||
dict['IMSI'] = IMSI
|
||||
print('updated', dict)
|
||||
|
||||
def add_dictsms(id, key, value):
|
||||
def add_dictsms(id, pricesms):
|
||||
dict = dictionary.get(id)
|
||||
value_ = float(value)
|
||||
if key in dict:
|
||||
dict[key] == value_
|
||||
else:
|
||||
print("Never should happen", id)
|
||||
|
||||
print("increasing sms dict key for dict: ",dict," for :",pricesms)
|
||||
dict["smscount"] += pricesms
|
||||
|
||||
def add_dictsmsprice(ICCID3, pricesms):
|
||||
dict2 = dictionary.get(ICCID3)
|
||||
dict2 = dictionary.get(ICCID2)
|
||||
print("section 3, add to sms")
|
||||
print(dict2)
|
||||
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)
|
||||
dictionary[ICCID] = {'IMSI': 0,'data': price, 'sms': 0.00000, 'other': 0.00000, 'smscount': 0}
|
||||
|
||||
xxx = []
|
||||
|
||||
print("Start section 2")
|
||||
with open(FILE2, newline='', encoding="utf-8") as csvfile2:
|
||||
reader2 = csv.DictReader(csvfile2, delimiter=',')
|
||||
@@ -105,36 +103,61 @@ with open(FILE2, newline='', encoding="utf-8") as csvfile2:
|
||||
IMSI = int(row['IMSI'])
|
||||
ICCID2 = ICCID3 = int(row['ICCID'])
|
||||
ICCID3 = int(ICCID2)
|
||||
print("Je to jeste ok? ",ICCID3)
|
||||
xxx.append(int(row['ICCID']))
|
||||
|
||||
|
||||
if ICCID2 in dictionary:
|
||||
print("Adding IMSI: ",IMSI ,"to dictionary: ", ICCID2)
|
||||
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")
|
||||
# with open(FILE3, newline='', encoding="utf-8") as csvfile3:
|
||||
# reader3 = csv.DictReader(csvfile3, delimiter=',')
|
||||
# for row in reader3:
|
||||
# print(xxx[1])
|
||||
# print("we got bad ICCIDfinal from section 2! :",xxx[5])
|
||||
# IMSI2 = int(row['IMSI'])
|
||||
# print(row['Nr. of SMS payload'])
|
||||
# print(row['Nr. of SMS MO'])
|
||||
# smspay = int(row['Nr. of SMS payload'])
|
||||
# smsmo = int(row['Nr. of SMS MO'])
|
||||
#
|
||||
#
|
||||
# price = smspay * smsmo * 1.28
|
||||
#
|
||||
#
|
||||
# print("Dict: ", dict)
|
||||
# for x in xxx:
|
||||
#
|
||||
# print("Adding SMSprice: ",price ,"to dictionary: ", x)
|
||||
#
|
||||
# add_dictsmsprice(x, price)
|
||||
#print(key,"→", val)
|
||||
if val == imsi:
|
||||
print("succesfuly paired: ", i)
|
||||
i += 1
|
||||
print("got it, IMSI: ", imsi," is paired to ICCID:", ICCID2)
|
||||
#add_dictsms(ICCID2, pricesms)
|
||||
print(dictionary[ICCID2])
|
||||
#sys.exit()
|
||||
|
||||
# just get the dictionary key by matching IMSI
|
||||
#dictionary = {'george': 16, 'amber': 19}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#sys.exit()
|
||||
|
||||
|
||||
|
||||
|
||||
#print("Adding SMSprice: ",price ,"to dictionary: ", x)
|
||||
#add_dictsmsprice(x, price)
|
||||
|
||||
|
||||
|
||||
|
||||
92
vdgdsp_final
Normal file
92
vdgdsp_final
Normal file
@@ -0,0 +1,92 @@
|
||||
import csv
|
||||
|
||||
FILE = 'Summarised_data_usage_per_ICCID_(STCU)_20211101_20211130_2021-12-02T94742084Z.CSV'
|
||||
FILE2 = 'Standard_Pairing_File___2021-12-02T1142395Z.CSV'
|
||||
FILE3 = 'VFGDSP202110_Summarised_SMS_usage_per_IMSI.CSV'
|
||||
|
||||
|
||||
class One(object):
|
||||
def __init__(self, iccid, imsi, price, smscount):
|
||||
self.iccid = iccid
|
||||
self.imsi = imsi
|
||||
self.price = price
|
||||
self.smscount = smscount
|
||||
|
||||
def __str__(self):
|
||||
return " iccid: %s, imsi: %s, price: %s, smscount: %s)" % (self.iccid, self.imsi, self.price, self.smscount)
|
||||
|
||||
|
||||
dict_by_iccid = {}
|
||||
with open(FILE, newline='', encoding="utf-8") as csvfile:
|
||||
reader = csv.DictReader(csvfile, delimiter=',')
|
||||
for row in reader:
|
||||
# print(row)
|
||||
iccid = int(row['ICCID'])
|
||||
#price = row['Sum Total Kbytes'].replace(',', '.')
|
||||
price = row['Sum Total Kbytes']
|
||||
price = price.replace(' ', '')
|
||||
# print(iccid, price)
|
||||
price = (2.23 * float(price)) / 1024
|
||||
|
||||
if iccid in dict_by_iccid:
|
||||
dict_by_iccid[iccid].price += price
|
||||
else:
|
||||
dict_by_iccid[iccid] = One(iccid=iccid, imsi=0, price=price,smscount=0)
|
||||
# dict_by_iccid = { iccid1: One(), iccid2:One(), iccid3:One(), }
|
||||
|
||||
# only add IMSI if possible
|
||||
with open(FILE2, newline='', encoding="utf-8") as csvfile2:
|
||||
reader2 = csv.DictReader(csvfile2, delimiter=',')
|
||||
for row in reader2:
|
||||
|
||||
imsi2 = int(row['IMSI'])
|
||||
iccid2 = int(row['ICCID'])
|
||||
|
||||
if iccid2 in dict_by_iccid:
|
||||
dict_by_iccid[iccid2].imsi = imsi2
|
||||
else:
|
||||
dict_by_iccid[iccid2] = One(iccid=iccid2, imsi=imsi2, price=0, smscount=0)
|
||||
|
||||
# dict_by_iccid = { iccid1: One(), iccid2:One(), iccid3:One(), }
|
||||
# new dictionary for easier look up
|
||||
dict_by_imsi = {}
|
||||
for i in dict_by_iccid.values():
|
||||
dict_by_imsi[i.imsi] = i
|
||||
# dict_by_imsi = { imsi1: One(), imsi2:One(), imsi3:One(), }
|
||||
|
||||
# add price for one imsi
|
||||
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'])
|
||||
imsi3 = int(row['IMSI'])
|
||||
# print("IMSI: ",imsi)
|
||||
# print("smspay: ",smspay)
|
||||
# print("smsmo: ", smsmo)
|
||||
|
||||
price = (smspay * 0.26) + (smsmo * 1.28)
|
||||
smscountnum = smspay + smsmo
|
||||
|
||||
if imsi3 in dict_by_imsi:
|
||||
dict_by_imsi[imsi3].price += price
|
||||
dict_by_imsi[imsi3].smscount += smscountnum
|
||||
else:
|
||||
dict_by_imsi[imsi3] = One(iccid=None, imsi=imsi3, price=price, smscount=smscountnum)
|
||||
|
||||
|
||||
with open('vystup_tadaaa.csv', 'w') as csv_file:
|
||||
for value in dict_by_imsi.values():
|
||||
print(value.iccid, value.imsi, value.price, value.smscount)
|
||||
writer = csv.writer(csv_file)
|
||||
writer.writerow([value.iccid, value.imsi,value.price,value.smscount])
|
||||
|
||||
|
||||
|
||||
#print(i)
|
||||
|
||||
# with open('dict.csv', 'w') as csv_file:
|
||||
# writer = csv.writer(csv_file)
|
||||
# for key, value in dict_by_imsi.items():
|
||||
# writer.writerow([key, value])
|
||||
|
||||
Reference in New Issue
Block a user