Browse Source

Full update file version and step count add

master
Ubuntu 2 years ago
parent
commit
7f31741f31
  1. 56
      smart_service/apis/publish_api.py
  2. 255
      smart_service/apis/update_validation.py

56
smart_service/apis/publish_api.py

@ -245,6 +245,7 @@ def new_publish(args, publish_type, vehicle, language, version):
# Save file (Internal/Global)
with open(file_name, 'w') as outfile:
outfile.write(json.dumps(json_file))
get_step_total_count(file_name)
# Remove previous internal publish file
if publish_type.lower() == 'internal':
@ -262,7 +263,10 @@ def new_publish(args, publish_type, vehicle, language, version):
and publish_type = 'Global' AND `language` = '{}' order by version desc limit 2 ;'''.format(vehicle,language),as_dict=True)
if pub_ver:
prev_update_ver = pub_ver[1]['version']
if pub_ver[0]['version'] != '1.00':
prev_update_ver = pub_ver[1]['version']
else:
prev_update_ver = pub_ver[0]['version']
full_update_file_name = full_update_path + vehicle + '/'+ '%s-%s-full_v%s.json' % (vehicle, language, version)
@ -270,6 +274,7 @@ def new_publish(args, publish_type, vehicle, language, version):
if version == '1.00':
with open(full_update_file_name, 'w') as outfile:
outfile.write(json.dumps(json_file))
get_step_total_count(full_update_file_name)
else:
prev_full_update_file = full_update_path + vehicle + '/'+ '%s-%s-full_v%s.json' % (vehicle, language, prev_update_ver)
@ -277,7 +282,9 @@ def new_publish(args, publish_type, vehicle, language, version):
list1.append(file_name)
list1.append(full_update_file_name)
final_update_file = merge_json_files(prev_full_update_file,file_name,full_update_file_name)
return file_name.split('public')[1],list1
get_step_total_count(final_update_file)
return file_name.split('public')[1]
except:
return "Failed to save file"
@ -513,6 +520,51 @@ def merge_json_files(old_json_path,new_json_path,out_file_path):
except Exception as e :
return e
def get_step_total_count(json_path):
with open(json_path) as json_file:
data = json.load(json_file)
total_count = calculate_total(data)
generate_json(data,json_path)
return total_count
def generate_json(data,json_path):
json_object = json.dumps(data)
with open(json_path, "w") as outfile:
outfile.write(json_object)
def calculate_total(data):
for variant in data['JSON']:
total_count = 0
step_count = 0
total_count += len(variant['Variant']['Assets'])
total_count += len(variant['Variant']['Systems'])
for system in variant['Variant']['Systems']:
total_count += len(system['Assets'])
total_count += len(system['Subsystems'])
for subsystem in system['Subsystems']:
try:
total_count += len(subsystem['Config Kilometer'])
except Exception as e:
pass
try:
total_count += len(subsystem['Procedure_details'])
except Exception as e:
pass
try:
for step in subsystem['Procedure_details']:
total_count += len(step['steps'])
step_count += len(step['steps'])
except Exception as e:
pass
variant['TotalCount'] = total_count
variant['StepCount'] = step_count
return data
# def get_data(args):
# try:
# docs_child = frappe.db.get_list('Publish_Docs', filters={'parent': args},

255
smart_service/apis/update_validation.py

@ -126,81 +126,25 @@ def check_vehicle_update(vehicle_list=None):
data1 = frappe.db.sql('''SELECT name,max(version) as version,vehicle_id,language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and vehicle_status='Active' order by version ASC;'''.format(
current_db_name, vehicle, l_id), as_dict=True)
if data1_global[0]['version']:
if data1[0]['version'] is not None:
if current_version == float(data1[0]['version']):
data1[0]['IsUpdateAvailable'] = "false"
data={}
data['Language']=l_id
data['IsUpdateAvailable'] = 'false'
data['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(data)
if data1[0]['version'] is not None:
if current_version == float(data1[0]['version']):
data1[0]['IsUpdateAvailable'] = "false"
data={}
data['Language']=l_id
data['IsUpdateAvailable'] = 'false'
data['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(data)
else:
if current_version < (float(data1_global[0]['version'])-1.00):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global' and vehicle_status='Active' and Version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/full_update/"+vehicle+"/"+vehicle+"-"+d['Language']+"-"+"full_v"+str(d['Version'])+".json"
get_step_total_count(base_url+file_name,)
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
except:
file_name= None
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e:
Vehicle_req_list.append({"Error":e})
elif current_version == (float(data1_global[0]['version'])-1.00):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global' and vehicle_status='Active' and Version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/global/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
except:
file_name= None
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e1:
Vehicle_req_list.append({"Error":e1})
elif current_version == float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
else:
if current_version < (float(data1_global[0]['version'])-1.00):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='{}' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, publish_type, current_version), as_dict=True)
and publish_type='Global' and vehicle_status='Active' and Version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_name="/files/json_files/full_update/"+vehicle+"/"+vehicle+"-"+d['Language']+"-"+"full_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
@ -216,17 +160,15 @@ def check_vehicle_update(vehicle_list=None):
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e2:
Vehicle_req_list.append({"Error":e2})
except Exception as e:
Vehicle_req_list.append({"Error":e})
elif (float(data1_global[0]['version'])-1.00) < current_version < float(data1_global[0]['version']):
Vehicle_req_list.append({'Cur_ver':current_version,"Global Ver":data1[0]['version']})
if current_version < float(data1[0]['version']):
Vehicle_req_list.append({"loop":4.1})
elif current_version == (float(data1_global[0]['version'])-1.00):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, current_version), as_dict=True)
Vehicle_req_list.append({"Data":'Append'})
and publish_type='Global' and vehicle_status='Active' and Version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, current_version), as_dict=True)
try:
for d in data:
try:
@ -237,7 +179,7 @@ def check_vehicle_update(vehicle_list=None):
d['Error']= None
except:
file_name= "/files/json_files/global/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_name= None
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
@ -246,43 +188,126 @@ def check_vehicle_update(vehicle_list=None):
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e2:
Vehicle_req_list.append({"Error":e2})
# else:
# Vehicle_req_list.append({"error2":"Else"})
except Exception as e1:
Vehicle_req_list.append({"Error":e1})
elif current_version > float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='{}' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id,publish_type, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
elif current_version == float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='{}' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, publish_type, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
except:
file_name= None
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e2:
Vehicle_req_list.append({"Error":e2})
elif (float(data1_global[0]['version'])-1.00) < current_version < float(data1_global[0]['version']):
Vehicle_req_list.append({'Cur_ver':current_version,"Global Ver":data1[0]['version']})
if current_version < float(data1[0]['version']):
Vehicle_req_list.append({"loop":4.1})
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, current_version), as_dict=True)
Vehicle_req_list.append({"Data":'Append'})
try:
for d in data:
try:
file_name="/files/json_files/global/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
except:
file_name= "/files/json_files/global/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e2:
Vehicle_req_list.append({"Error":e2})
# else:
# Vehicle_req_list.append({"error2":"Else"})
elif current_version > float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='{}' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id,publish_type, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
except:
file_name= "/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e3:
Vehicle_req_list.append({'Error':e3})
# else:
# Vehicle_req_list.append({'Error':"Else 3"})
except:
file_name= "/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
else:
Vehicle_req_list.append(
{'Language': l_id, 'IsUpdateAvailable': 'false', 'CurrentVersion': float(current_version)})
else:
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='{}' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, publish_type, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e3:
Vehicle_req_list.append({'Error':e3})
# else:
# Vehicle_req_list.append({'Error':"Else 3"})
except:
file_name= None
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e2:
Vehicle_req_list.append({"Error":e2})
else:
Vehicle_req_list.append(
{'Language': l_id, 'IsUpdateAvailable': 'false', 'CurrentVersion': float(current_version)})
response['Vehicle'] = vehicle
response['VehicleReqList'] = Vehicle_req_list
return response
@ -295,10 +320,10 @@ def check_vehicle_update(vehicle_list=None):
else:
return {"status": 0, "error": "Check Parameter: vehicle list"}
def get_step_total_count(json_path):
with open(json_path) as json_file:
data = json.load(json_file)
data = calculate_step(data)
data = calculate_total(data)
generate_json(data, json_path)
@ -313,9 +338,7 @@ def generate_json(data, json_path):
def calculate_total(data):
total_count = 0
for variant in data['JSON']:
total_count += len(variant['Variant']['Assets'])
total_count += len(variant['Variant']['Systems'])
for system in variant['Variant']['Systems']:

Loading…
Cancel
Save