Compare commits

...

4 Commits

Author SHA1 Message Date
05840e59e8 final 2022-02-14 18:59:41 +01:00
9f12cd1c48 Delete 'TMGDSP202105.CSV' 2022-02-14 17:58:43 +00:00
7add5342b7 Delete 'ucetnictvi_pokusy.py' 2022-02-14 17:58:29 +00:00
3079743a7a Delete 'vdgdsp.py' 2022-02-14 17:58:21 +00:00
4 changed files with 1 additions and 36271 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,156 +0,0 @@
import csv
from datetime import datetime
import sys
import pandas as pd
FILE = 'TMGDSP202110.CSV'
#usrmonth = input("Month to be processed: ")
countofnotsms = int(1)
dictionary = {}
def add_dict(id, key, value):
dict = dictionary.get(id)
if key in dict:
print("increasing notsms dict key for: ",value,"key IS: ",key)
dict[key] += value
print("end state: ",dict[key])
dict[key] = round(dict[key],5)
print("key: ",key)
else:
print("Never should happen", id)
def add_dictsms(id, pricesms):
dict = dictionary.get(id)
print("increasing sms dict key for dict: ",dict," for :",pricesms)
dict["smscount"] += pricesms
#MAIN
with open(FILE, newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile, delimiter=';')
for row in reader:
#print(row)
if row['MSISDN'] == '':
continue #skip empty MSISDN
#if row['BILLED_PERIOD_START'] == '':
#continue
#my_string = row['BILLED_PERIOD_START']
#my_string = '2021-09-06'
#print(my_string)
#try:
#my_date = datetime.strptime(my_string, "%Y-%m-%d")
#except:
#print("An exception occurred, current my_string is: ", my_string)
#sys.exit(1)
#print(row['BILLED_PERIOD_START'])
#print(my_date.month)
#if my_date.month != '5':
#continue #skip bad dates
MSISDN = int(row['MSISDN'])
ICCID = int(row['ICCID'])
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":
typ = "data"
elif row['CHARGE_TYPE'] == "Poplatky za roamingový datový provoz":
typ = "data"
elif row['CHARGE_TYPE'] == "Poplatky za národní datový provoz":
typ = "data"
elif row['CHARGE_TYPE'] == "Poplatky za roamingový SMS provoz":
typ = "sms"
elif row['CHARGE_TYPE'] == "Poplatky za národní SMS provoz":
typ = "sms"
else:
typ = 'other'
if row['INCREMENT'] == "SMS":
pricesms = int(row['RATED_AMOUNT'])
else:
pricesms = 0
#only if not exist create new record in dictionary for ID
if not MSISDN in dictionary:
dictionary[MSISDN] = {'ICCID':ICCID,'data':0.00000, 'sms':0.00000, 'other':0.00000, 'smscount':pricesms}
print("Creating new dictionary: ", dictionary[MSISDN])
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)
#ptry:
#print(dictionary[436761890319959]) #one with both types
#pexcept:
#pprint("Required unit is not in our set")
#psys.exit(1)
#pprint(len(dictionary.keys()))
#for key, value in dictionary.items():
#print(key, ' : ', value)
print("Count of units: ", len(dictionary.keys()))
#print("Count of sms: ",countofsms)
#for dict_value in dictionary:
# type(dict_value)
# #for k, v in dict_value.items():
#with open('fakturace_tmgdsp_export_20211110v2.csv', 'w') as f:
# for key in dictionary.keys():
# print(key,dictionary[key])
# f.write("%s,%s\n"%(key,dictionary[key]))
csv_columns = ['takhleuztoneudelam', 'ICCID', 'data', 'sms', 'other', 'smscount']
try:
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}
row.update(val)
writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
writer.writerow(row)
except IOError:
print(f"I/O error: {IOError}")

204
vdgdsp.py
View File

@@ -1,204 +0,0 @@
# coding: utf8
import time
import csv
from datetime import datetime
import sys
from pprint import pprint
FILE = 'VFGDSP202110_Summarised_data_usage_per_ICCID.CSV'
FILE2 = 'Standard_Pairing_File___2021-11-15T93331674Z.CSV'
FILE3 = 'VFGDSP202110_Summarised_SMS_usage_per_IMSI.CSV'
#usrmonth = input("Month to be processed: ")
#usrmonth = int(usrmonth)
usrmonth = int(5)
dictionary = {}
def add_dict(ICCID, IMSI):
dict = dictionary.get(ICCID)
print("Dict: ",dict)
print("Got IMSI: ", IMSI,"to add to dict: ",ICCID)
print("OK")
dict[ICCID] += IMSI
def add_dict2(ICCID, IMSI):
dict = dictionary.get(ICCID)
print("Dict: ",dict)
print("Got IMSI: ", IMSI,"to add to dict: ",ICCID)
print("OK")
dict['IMSI'] = IMSI
print('updated', dict)
def add_dictsms(id, pricesms):
dict = dictionary.get(id)
print("increasing sms dict key for dict: ",dict," for :",pricesms)
dict["smscount"] += pricesms
def add_dictsmsprice(ICCID3, pricesms):
dict2 = dictionary.get(ICCID2)
print("section 3, add to sms")
print(dict2)
print("increasing sms dict key for dict: ",dict2 , " for :", pricesms)
dict["x"] == pricesms
# MAIN
print("Start")
with open(FILE, newline='', encoding="utf-8") as csvfile:
reader = csv.DictReader(csvfile, delimiter=',')
for row in reader:
# print(row)
#if row['Telefonní číslo'] == '':
#continue # skip empty MSISDN
#if row['Začátek fakturačního období'] == '':
#continue
#my_string = row['Začátek fakturačního období']
# my_string = '2021-09-06'
#print("start date: ", my_string)
#try:
#my_date = datetime.strptime(my_string, "%d.%m.%Y")
#except:
#print("An exception occurred, current my_string is: ", my_string)
#sys.exit(1)
# print(row['BILLED_PERIOD_START'])
# print(my_date.month)
#if usrmonth != my_date.month:
#print("skipping bad date")
#continue # skip bad dates
#MSISDN = int(row['Telefonní číslo'])
print(row['ICCID'])
ICCID = int(row['ICCID'])
price = row['Sum Total Kbytes'].replace(',', '.')
price = price.replace(' ', '')
print(price)
price = (2.23*float(price))/1024
# only if not exist create new record in dictionary for ID
if not ICCID in dictionary:
print("Creating dictionary: ", ICCID)
dictionary[ICCID] = {'IMSI': 0,'data': price, 'sms': 0.00000, 'other': 0.00000, 'smscount': 0}
print("Start section 2")
with open(FILE2, newline='', encoding="utf-8") as csvfile2:
reader2 = csv.DictReader(csvfile2, delimiter=',')
for row in reader2:
print(row['IMSI'])
IMSI = int(row['IMSI'])
ICCID2 = ICCID3 = int(row['ICCID'])
ICCID3 = int(ICCID2)
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(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)
# print("Start section 3")
# with open(FILE3, newline='', encoding="utf-8") as csvfile3:
# reader3 = csv.DictReader(csvfile3, delimiter=',')
# for row in reader3:
# print(row['ICCID'])
# try:
# print(dictionary[436761890319959]) #one with both types
# except:
# print("Required unit is not in our set")
# sys.exit(1)
# print(len(dictionary.keys()))
# for key, value in dictionary.items():
# print(key, ' : ', value)
print("Count of units: ", len(dictionary.keys()))
with open('export_vfgdsp202110v1.csv', 'w') as f:
for key in dictionary.keys():
f.write("%s,%s\n" % (key, dictionary[key]))
csv_columns = ['takhleuztoneudelam', 'IMSI','data', 'sms', 'other', 'smscount']
try:
with open('export_vfgdsp_202110v1.csv', 'w') as csvfile:
w = csv.DictWriter(sys.stdout, csv_columns)
for key, val in sorted(dictionary.items()):
row = {'takhleuztoneudelam': key}
row.update(val)
writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
writer.writerow(row)
except IOError:
print(f"I/O error: {IOError}")

View File

@@ -80,7 +80,7 @@ with open('vystup_tadaaa.csv', 'w') as csv_file:
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("just messing with git")
#print(i)