Browse Source

code formatting for fFeedback, installation, login, model download n model hit reports

master
administrator 11 months ago
parent
commit
19e2630899
  1. 79
      smart_service/add_ons/report/feedback_report/feedback_report.py
  2. 64
      smart_service/add_ons/report/installation_report/installation_report.py
  3. 95
      smart_service/add_ons/report/login_report/login_report.py
  4. 103
      smart_service/add_ons/report/model_download_report/model_download_report.py
  5. 236
      smart_service/add_ons/report/model_hit_report/model_hit_report.py

79
smart_service/add_ons/report/feedback_report/feedback_report.py

@ -3,46 +3,61 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _ from frappe import msgprint, _
import sys import sys
sys.tracebacklimit=0 sys.tracebacklimit = 0
def execute(filters=None): def execute(filters=None):
columns, data = [], [] columns, data = [], []
columns = get_columns() columns = get_columns()
data = get_data(filters) data = get_data(filters)
return columns, data return columns, data
def get_data(filters): def get_data(filters):
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
data = frappe.db.sql("""select uf.name,uf.date,uf.subject,uf.user_name,uf.status,uf.attachments,uf.closure_date,uf.closed_by, data = frappe.db.sql("""select uf.name,uf.date,uf.subject,uf.user_name,uf.status,uf.attachments,uf.closure_date,uf.closed_by,
uf.description,uf.feedback_type,dealer.dealer_code,dealer.zone,dealer.dealer_name,uf.closure_date,uf.closed_by, uf.description,uf.feedback_type,dealer.dealer_code,dealer.zone,dealer.dealer_name,uf.closure_date,uf.closed_by,
dealer.area,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name from {0}.`tabUser Feedback` uf,{0}.`tabApp Dealer` dealer,{0}.`tabApp Users` au dealer.area,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name from {0}.`tabUser Feedback` uf,{0}.`tabApp Dealer` dealer,{0}.`tabApp Users` au
where uf.user_name = au.name and where uf.user_name = au.name and
(date(uf.modified) between '{1}' and '{2}') group by uf.name ORDER BY uf.date DESC""".format(current_db_name,filters.get('from_date'), filters.get('to_date')), as_dict=1) (date(uf.modified) between '{1}' and '{2}') group by uf.name ORDER BY uf.date DESC""".format(current_db_name, filters.get('from_date'), filters.get('to_date')), as_dict=1)
if data: if data:
return data return data
else: else:
frappe.msgprint('No Data for Selected Filters.') frappe.msgprint('No Data for Selected Filters.')
def get_columns():
columns = [
{"label": _("<b>User ID</b>"), "fieldname": "user_id", "fieldtype":"Data","width": 100},
{"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 150},
{"label": _("<b>Date</b>"), "fieldname": "date", "fieldtype": "Date", "width": 100},
{"label": _("<b>Feedback ID</b>"), "fieldname": "name", "fieldtype": "Link", "options":"User Feedback","width": 120},
{"label": _("<b>Feedback Type</b>"), "fieldname": "feedback_type", "fieldtype": "Data", "width": 120},
{"label": _("<b>Feedback Title</b>"), "fieldname": "subject", "fieldtype": "Data", "width": 120},
{"label": _("<b>Feedback Description</b>"), "fieldname": "description", "fieldtype": "Text Editor", "width": 250},
{"label": _("<b>Attachments</b>"), "fieldname": "attachments", "fieldtype": "Data", "width": 100},
{"label": _("<b>Feedback Status</b>"), "fieldname": "status", "fieldtype": "Data", "width": 100},
{"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 100},
{"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 140},
{"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 120},
{"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype": "Data", "width": 150},
{"label": _("<b>Closure Date</b>"), "fieldname": "closure_date", "fieldtype": "Data", "width": 150},
{"label": _("<b>Closed By</b>"), "fieldname": "closed_by", "fieldtype": "Data", "width": 120}
]
return columns
def get_columns():
columns = [
{"label": _("<b>User ID</b>"), "fieldname": "user_id",
"fieldtype": "Data", "width": 100},
{"label": _("<b>User Name</b>"), "fieldname": "user_name",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Date</b>"), "fieldname": "date",
"fieldtype": "Date", "width": 100},
{"label": _("<b>Feedback ID</b>"), "fieldname": "name",
"fieldtype": "Link", "options": "User Feedback", "width": 120},
{"label": _("<b>Feedback Type</b>"), "fieldname": "feedback_type",
"fieldtype": "Data", "width": 120},
{"label": _("<b>Feedback Title</b>"), "fieldname": "subject",
"fieldtype": "Data", "width": 120},
{"label": _("<b>Feedback Description</b>"), "fieldname": "description",
"fieldtype": "Text Editor", "width": 250},
{"label": _("<b>Attachments</b>"), "fieldname": "attachments",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Feedback Status</b>"), "fieldname": "status",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Zone</b>"), "fieldname": "zone",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Area Office</b>"), "fieldname": "area",
"fieldtype": "Data", "width": 140},
{"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code",
"fieldtype": "Data", "width": 120},
{"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Closure Date</b>"), "fieldname": "closure_date",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Closed By</b>"), "fieldname": "closed_by",
"fieldtype": "Data", "width": 120}
]
return columns

64
smart_service/add_ons/report/installation_report/installation_report.py

@ -5,42 +5,54 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _ from frappe import msgprint, _
def execute(filters=None): def execute(filters=None):
columns, data = [], [] columns, data = [], []
columns = get_columns() columns = get_columns()
data = get_data(filters) data = get_data(filters)
return columns, data return columns, data
def get_data(filters): def get_data(filters):
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
data = frappe.db.sql("""select dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name,dealer.dealer_code,dealer.dealer_name,dealer.area,ad.os,ad.os_version, data = frappe.db.sql("""select dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name,dealer.dealer_code,dealer.dealer_name,dealer.area,ad.os,ad.os_version,
al.device,ad.device_id,ad.app_current_version,al.type as type,ad.device_type,al.date_time_stamp,al.creation,ad.last_login as date,al.date_time_stamp as time,time(al.date_time_stamp) as last_time al.device,ad.device_id,ad.app_current_version,al.type as type,ad.device_type,al.date_time_stamp,al.creation,ad.last_login as date,al.date_time_stamp as time,time(al.date_time_stamp) as last_time
from {0}.`tabApp Log` al, {0}.`tabApp Device` ad, {0}.`tabApp Users` au, {0}.`tabApp Dealer` dealer from {0}.`tabApp Log` al, {0}.`tabApp Device` ad, {0}.`tabApp Users` au, {0}.`tabApp Dealer` dealer
where where
al.device = ad.name and al.user = au.name and au.dealer = dealer.name and (al.type = 'Installed' or al.type = 'Reinstalled') and al.device = ad.name and al.user = au.name and au.dealer = dealer.name and (al.type = 'Installed' or al.type = 'Reinstalled') and
(date(al.modified) between '{1}' and '{2}') ORDER BY ad.last_login DESC""".format(current_db_name,filters.get('from_date'), filters.get('to_date')), as_dict=1) (date(al.modified) between '{1}' and '{2}') ORDER BY ad.last_login DESC""".format(current_db_name, filters.get('from_date'), filters.get('to_date')), as_dict=1)
if data: if data:
return data return data
else: else:
frappe.msgprint('No Data for Selected Filters.') frappe.msgprint('No Data for Selected Filters.')
def get_columns(): def get_columns():
columns = [ columns = [
{"label": _("<b>User ID</b>"), "fieldname": "user_id", "fieldtype": "Data", "width": 100}, {"label": _("<b>User ID</b>"), "fieldname": "user_id",
{"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 150}, "fieldtype": "Data", "width": 100},
{"label": _("<b>Installation</b>"), "fieldname": "device", "fieldtype": "Data","width": 100}, {"label": _("<b>User Name</b>"), "fieldname": "user_name",
{"label": _("<b>App Version No</b>"), "fieldname": "app_current_version", "fieldtype": "Data", "width": 150}, "fieldtype": "Data", "width": 150},
{"label": _("<b>Activity Type</b>"), "fieldname": "type", "fieldtype": "Data","width": 150}, {"label": _("<b>Installation</b>"), "fieldname": "device",
{"label": _("<b>Device</b>"), "fieldname": "device_type", "fieldtype": "Data","width": 100}, "fieldtype": "Data", "width": 100},
{"label": _("<b>Device ID</b>"), "fieldname": "device_id", "fieldtype": "Data", "width": 150}, {"label": _("<b>App Version No</b>"), "fieldname": "app_current_version",
{"label": _("<b>Device OS</b>"), "fieldname": "os", "fieldtype": "Data", "width": 100}, "fieldtype": "Data", "width": 150},
{"label": _("<b>OS Version</b>"), "fieldname": "os_version", "fieldtype": "Data", "width": 100}, {"label": _("<b>Activity Type</b>"), "fieldname": "type",
{"label": _("<b>App Installation Date</b>"), "fieldname": "date_time_stamp", "fieldtype": "DateTime","width": 200}, "fieldtype": "Data", "width": 150},
{"label": _("<b>App Last Accessed Date</b>"), "fieldname": "date", "fieldtype": "DateTime","width": 200} {"label": _("<b>Device</b>"), "fieldname": "device_type",
] "fieldtype": "Data", "width": 100},
return columns {"label": _("<b>Device ID</b>"), "fieldname": "device_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Device OS</b>"), "fieldname": "os",
"fieldtype": "Data", "width": 100},
{"label": _("<b>OS Version</b>"), "fieldname": "os_version",
"fieldtype": "Data", "width": 100},
{"label": _("<b>App Installation Date</b>"),
"fieldname": "date_time_stamp", "fieldtype": "DateTime", "width": 200},
{"label": _("<b>App Last Accessed Date</b>"),
"fieldname": "date", "fieldtype": "DateTime", "width": 200}
]
return columns

95
smart_service/add_ons/report/login_report/login_report.py

@ -3,34 +3,22 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _ from frappe import msgprint, _
from frappe.utils import cstr, flt, cint,TIME_FORMAT,DATE_FORMAT,DATETIME_FORMAT, now_datetime
from datetime import date, time, datetime, timedelta
from frappe.utils import now
import datetime
def execute(filters=None): def execute(filters=None):
columns, data = [], [] columns, data = [], []
columns = get_columns() columns = get_columns()
data = get_data(filters) data = get_data(filters)
return columns, data return columns, data
def get_data(filters):
current_db_name = frappe.conf.get("db_name")
from_date = filters.get('from_date')
to_date = filters.get('to_date')
data_test = frappe.db.sql("""select count(al.name) as count,dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name,
dealer.dealer_code,dealer.dealer_name,dealer.area,ad.os,ad.os_version,
ad.device_type,ad.device_id,ad.app_current_version,al.type,al.latitude,al.longitude,al.date_time_stamp,al.creation,
date(al.date_time_stamp) as date,time(ad.last_login) as time
from {0}.`tabApp Log` al,{0}.`tabApp Device` ad,{0}.`tabApp Users` au,{0}.`tabApp Dealer` dealer
where
al.device = ad.name and al.user = au.name and au.dealer = dealer.name and al.type = 'Logged in' and
(date(al.modified) between '{1}' and '{2}') group by al.user,ad.device_id,date(al.date_time_stamp)""".format(current_db_name,from_date,to_date), as_dict=1)
def get_data(filters):
current_db_name = frappe.conf.get("db_name")
from_date = filters.get('from_date')
to_date = filters.get('to_date')
data = frappe.db.sql("""select dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name, data = frappe.db.sql("""select dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name,
dealer.dealer_code,dealer.dealer_name,dealer.area,ad.os,ad.os_version, dealer.dealer_code,dealer.dealer_name,dealer.area,ad.os,ad.os_version,
ad.device_type,ad.device_id,ad.app_current_version,al.type,date(al.date_time_stamp) as date, ad.device_type,ad.device_id,ad.app_current_version,al.type,date(al.date_time_stamp) as date,
al.latitude, al.longitude, au.name, al.device, time(al.date_time_stamp) as last_login_time, mal.count from {current_db_name}.`tabApp Log` al, al.latitude, al.longitude, au.name, al.device, time(al.date_time_stamp) as last_login_time, mal.count from {current_db_name}.`tabApp Log` al,
@ -41,41 +29,32 @@ def get_data(filters):
and mal.user=au.name and mal.user=au.name
and au.dealer = dealer.name and au.dealer = dealer.name
and al.device = ad.name and al.device = ad.name
and mal.date_time_stam=al.date_time_stamp ORDER BY date DESC; """.format(current_db_name = current_db_name,from_date= from_date,to_date=to_date), as_dict=1) and mal.date_time_stam=al.date_time_stamp ORDER BY date DESC; """.format(current_db_name=current_db_name, from_date=from_date, to_date=to_date), as_dict=1)
if data: if data:
return data return data
else: else:
frappe.msgprint('No Data for Selected Filters.') frappe.msgprint('No Data for Selected Filters.')
def get_columns():
columns = [
{"label": _("<b>User ID</b>"), "fieldname": "user_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 150},
{"label": _("<b>Date</b>"), "fieldname": "date", "fieldtype": "Date", "width": 100},
{"label": _("<b>Time</b>"), "fieldname": "last_login_time", "fieldtype": "DateTime", "width": 130},
{"label": _("<b>Count</b>"), "fieldname": "count", "fieldtype": "Data", "width": 100},
{"label": _("<b>Device ID</b>"), "fieldname": "device_id", "fieldtype": "Data", "width": 100},
{"label": _("<b>Device</b>"), "fieldname": "device_type", "fieldtype": "Data", "width": 130},
{"label": _("<b>Latitude</b>"), "fieldname": "latitude", "fieldtype": "Data", "width": 100},
{"label": _("<b>Longitude</b>"), "fieldname": "longitude", "fieldtype": "Data", "width": 100}
]
return columns
# def get_columns():
# columns = [
# {"label": _("<b>Date</b>"), "fieldname": "date", "fieldtype": "Date", "width": 100},
# {"label": _("<b>Time</b>"), "fieldname": "last_login_time", "fieldtype": "DateTime", "width": 130},
# {"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 100},
# {"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 100},
# {"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype":"Data","width": 150},
# {"label": _("<b>Device</b>"), "fieldname": "device_type", "fieldtype": "Data", "width": 100},
# {"label": _("<b>Device ID</b>"), "fieldname": "device_id", "fieldtype": "Data", "width": 150},
# {"label": _("<b>User ID</b>"), "fieldname": "user_id", "fieldtype": "Data", "width": 150},
# {"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 100},
# {"label": _("<b>Latitude</b>"), "fieldname": "latitude", "fieldtype": "Data", "width": 100},
# {"label": _("<b>Longitude</b>"), "fieldname": "longitude", "fieldtype": "Data", "width": 100},
# {"label": _("<b>Count</b>"), "fieldname": "count", "fieldtype": "Data", "width": 100},
# ]
# return columns
def get_columns():
columns = [
{"label": _("<b>User ID</b>"), "fieldname": "user_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>User Name</b>"), "fieldname": "user_name",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Date</b>"), "fieldname": "date",
"fieldtype": "Date", "width": 100},
{"label": _("<b>Time</b>"), "fieldname": "last_login_time",
"fieldtype": "DateTime", "width": 130},
{"label": _("<b>Count</b>"), "fieldname": "count",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Device ID</b>"), "fieldname": "device_id",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Device</b>"), "fieldname": "device_type",
"fieldtype": "Data", "width": 130},
{"label": _("<b>Latitude</b>"), "fieldname": "latitude",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Longitude</b>"), "fieldname": "longitude",
"fieldtype": "Data", "width": 100}
]
return columns

103
smart_service/add_ons/report/model_download_report/model_download_report.py

@ -3,70 +3,79 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _ from frappe import msgprint, _
import datetime
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
def execute(filters=None): def execute(filters=None):
columns, data = [], [] columns, data = [], []
columns = get_columns() columns = get_columns()
data = get_data(filters) data = get_data(filters)
return columns, data return columns, data
def get_data(filters): def get_data(filters):
if filters.get('model'): if filters.get('model'):
from_date=filters['from_date'] from_date = filters['from_date']
to_date=filters['to_date'] to_date = filters['to_date']
modelfilter=filters['model'] modelfilter = filters['model']
data = frappe.db.sql("""SELECT date(date) as date, device_id, device_type, app_version, download_vehicle_id, download_vehicle_version, data = frappe.db.sql("""SELECT date(date) as date, device_id, device_type, app_version, download_vehicle_id, download_vehicle_version,
download_vehicle_date, download_vehicle_language_id, download_vehicle_current_version, mh.user_id, download_vehicle_date, download_vehicle_language_id, download_vehicle_current_version, mh.user_id,
login_name,concat(first_name,' ',last_name) as user_name login_name,concat(first_name,' ',last_name) as user_name
FROM `tabModel Hit` mh FROM `tabModel Hit` mh
left join `tabApp Users` au on mh.user_id = au.user_id left join `tabApp Users` au on mh.user_id = au.user_id
WHERE download_vehicle_id='{1}' and (date(date) between '{2}' and '{3}') ORDER BY download_vehicle_id,date DESC;""".format(current_db_name, WHERE download_vehicle_id='{1}' and (date(date) between '{2}' and '{3}') ORDER BY download_vehicle_id,date DESC;""".format(current_db_name,
modelfilter, from_date, to_date), as_dict=1) modelfilter, from_date, to_date), as_dict=1)
for d in data: for d in data:
d['download_vehicle_id']=modelfilter d['download_vehicle_id'] = modelfilter
if d['user_id']: if d['user_id']:
try: try:
dealer_info=frappe.db.sql("""SELECT dealer FROM {0}.`tabApp Users` where user_id='{1}';""".format(current_db_name, d['user_id']), as_dict=1) dealer_info = frappe.db.sql("""SELECT dealer FROM {0}.`tabApp Users` where user_id='{1}';""".format(
dealer_info=dealer_info[-1]['dealer'] current_db_name, d['user_id']), as_dict=1)
dealer_details=frappe.db.sql("""SELECT dealer_name,dealer_code,area as location,zone FROM {0}.`tabApp Dealer` dealer_info = dealer_info[-1]['dealer']
dealer_details = frappe.db.sql("""SELECT dealer_name,dealer_code,area as location,zone FROM {0}.`tabApp Dealer`
where name='{1}';""".format(current_db_name, dealer_info), as_dict=1) where name='{1}';""".format(current_db_name, dealer_info), as_dict=1)
dealer_details=dealer_details[-1] dealer_details = dealer_details[-1]
d['dealer_code']=dealer_details['dealer_code'] d['dealer_code'] = dealer_details['dealer_code']
d['dealer_name']=dealer_details['dealer_name'] d['dealer_name'] = dealer_details['dealer_name']
d['area']=dealer_details['location'] d['area'] = dealer_details['location']
d['zone']=dealer_details['zone'] d['zone'] = dealer_details['zone']
except: except:
pass pass
if data: if data:
return data return data
else: else:
frappe.msgprint('No Data for Selected Filters.') frappe.msgprint('No Data for Selected Filters.')
def get_columns(): def get_columns():
columns = [ columns = [
{"label": _("<b>Date</b>"), "fieldname": "date", "fieldtype": "Date", "width": 150}, {"label": _("<b>Date</b>"), "fieldname": "date",
{"label": _("<b>User ID</b>"), "fieldname": "login_name", "fieldtype": "Data", "width": 125}, "fieldtype": "Date", "width": 150},
{"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 125}, {"label": _("<b>User ID</b>"), "fieldname": "login_name",
{"label": _("<b>Downloaded Vehicle</b>"), "fieldname": "download_vehicle_id", "fieldtype": "Data", "width": 150}, "fieldtype": "Data", "width": 125},
{"label": _("<b>Downloaded Language</b>"), "fieldname": "download_vehicle_language_id", "fieldtype": "Data", "width": 150}, {"label": _("<b>User Name</b>"), "fieldname": "user_name",
{"label": _("<b>Downloaded Version</b>"), "fieldname": "download_vehicle_current_version", "fieldtype": "Data", "width": 150}, "fieldtype": "Data", "width": 125},
{"label": _("<b>App Version</b>"), "fieldname": "app_version", "fieldtype": "Data", "width": 150}, {"label": _("<b>Downloaded Vehicle</b>"),
# {"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 100}, "fieldname": "download_vehicle_id", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 150}, {"label": _("<b>Downloaded Language</b>"),
# {"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 150}, "fieldname": "download_vehicle_language_id", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype": "Data", "width": 150}, {"label": _("<b>Downloaded Version</b>"),
{"label": _("<b>Device</b>"), "fieldname": "device_id", "fieldtype": "Data", "width": 150}, "fieldname": "download_vehicle_current_version", "fieldtype": "Data", "width": 150},
{"label": _("<b>Device Type</b>"), "fieldname": "device_type", "fieldtype": "Data", "width": 150} {"label": _("<b>App Version</b>"), "fieldname": "app_version",
"fieldtype": "Data", "width": 150},
# {"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 100},
# {"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype": "Data", "width": 150},
{"label": _("<b>Device</b>"), "fieldname": "device_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Device Type</b>"), "fieldname": "device_type",
"fieldtype": "Data", "width": 150}
] ]
return columns return columns

236
smart_service/add_ons/report/model_hit_report/model_hit_report.py

@ -4,92 +4,94 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _ from frappe import msgprint, _
import datetime import datetime
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
def execute(filters=None): def execute(filters=None):
columns, data = [], [] columns, data = [], []
columns = get_columns() columns = get_columns()
data = get_data(filters) data = get_data(filters)
return columns, data return columns, data
def get_data(filters): def get_data(filters):
if filters.get('variant') and filters.get('model'): if filters.get('variant') and filters.get('model'):
from_date=filters['from_date'] from_date = filters['from_date']
to_date=filters['to_date'] to_date = filters['to_date']
modelfilter=filters['model'] modelfilter = filters['model']
variantfilter=filters['variant'] variantfilter = filters['variant']
variantfilter=variantfilter.split(".") variantfilter = variantfilter.split(".")
data = frappe.db.sql("""SELECT date as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id, data = frappe.db.sql("""SELECT date as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,
count(*) as count, user_id, language FROM {0}.`tabModel Usage` WHERE vehicle_id='{1}' and variant_id='{2}' and (date(date) between '{3}' and '{4}') count(*) as count, user_id, language FROM {0}.`tabModel Usage` WHERE vehicle_id='{1}' and variant_id='{2}' and (date(date) between '{3}' and '{4}')
GROUP BY date(date), user_id, module_id, device_id, vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id, GROUP BY date(date), user_id, module_id, device_id, vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,
language language
order by module_id,vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,language,date DESC; order by module_id,vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,language,date DESC;
""".format(current_db_name, modelfilter, variantfilter[1], from_date, to_date), as_dict=1) """.format(current_db_name, modelfilter, variantfilter[1], from_date, to_date), as_dict=1)
for d in data: for d in data:
if d['user_id']: if d['user_id']:
try: try:
dealer_info=frappe.db.sql("""SELECT dealer FROM {0}.`tabApp Users` where user_id='{1}';""".format(current_db_name, d['user_id']), as_dict=1) dealer_info = frappe.db.sql("""SELECT dealer FROM {0}.`tabApp Users` where user_id='{1}';""".format(
dealer_info=dealer_info[-1]['dealer'] current_db_name, d['user_id']), as_dict=1)
dealer_details=frappe.db.sql("""SELECT dealer_name,dealer_code,area as location,zone FROM {0}.`tabApp Dealer` where name='{1}';""".format(current_db_name, dealer_info), as_dict=1) dealer_info = dealer_info[-1]['dealer']
dealer_details=dealer_details[-1] dealer_details = frappe.db.sql("""SELECT dealer_name,dealer_code,area as location,zone FROM {0}.`tabApp Dealer` where name='{1}';""".format(
d['dealer_code']=dealer_details['dealer_code'] current_db_name, dealer_info), as_dict=1)
d['dealer_name']=dealer_details['dealer_name'] dealer_details = dealer_details[-1]
d['area']=dealer_details['location'] d['dealer_code'] = dealer_details['dealer_code']
d['zone']=dealer_details['zone'] d['dealer_name'] = dealer_details['dealer_name']
except: d['area'] = dealer_details['location']
pass d['zone'] = dealer_details['zone']
except:
if data: pass
return data
else: if data:
frappe.msgprint('No Data for Selected Filters.') return data
else:
elif filters.get('model'): frappe.msgprint('No Data for Selected Filters.')
from_date=filters['from_date']
to_date=filters['to_date'] elif filters.get('model'):
modelfilter=filters['model'] from_date = filters['from_date']
to_date = filters['to_date']
data = frappe.db.sql("""SELECT date(date) as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id, procedure_id, modelfilter = filters['model']
data = frappe.db.sql("""SELECT date(date) as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id, procedure_id,
steps_id, count(*) as count, user_id, language FROM {0}.`tabModel Usage` WHERE vehicle_id='{1}' and (date(date) between '{2}' and '{3}') steps_id, count(*) as count, user_id, language FROM {0}.`tabModel Usage` WHERE vehicle_id='{1}' and (date(date) between '{2}' and '{3}')
GROUP BY date(date), user_id, module_id, device_id, vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,language GROUP BY date(date), user_id, module_id, device_id, vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,language
order by module_id,vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,language; order by module_id,vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,language;
;""".format(current_db_name, modelfilter, from_date, to_date), as_dict=1) ;""".format(current_db_name, modelfilter, from_date, to_date), as_dict=1)
for d in data: for d in data:
if d['user_id']: if d['user_id']:
try: try:
dealer_info=frappe.db.sql("""SELECT dealer FROM {0}.`tabApp Users` where user_id='{1}';""".format(current_db_name, d['user_id']), as_dict=1) dealer_info = frappe.db.sql("""SELECT dealer FROM {0}.`tabApp Users` where user_id='{1}';""".format(
dealer_info=dealer_info[-1]['dealer'] current_db_name, d['user_id']), as_dict=1)
dealer_details=frappe.db.sql("""SELECT dealer_name,dealer_code,area as location,zone FROM {0}.`tabApp Dealer` where name='{1}';""".format(current_db_name, dealer_info), as_dict=1) dealer_info = dealer_info[-1]['dealer']
dealer_details=dealer_details[-1] dealer_details = frappe.db.sql("""SELECT dealer_name,dealer_code,area as location,zone FROM {0}.`tabApp Dealer` where name='{1}';""".format(
d['dealer_code']=dealer_details['dealer_code'] current_db_name, dealer_info), as_dict=1)
d['dealer_name']=dealer_details['dealer_name'] dealer_details = dealer_details[-1]
d['area']=dealer_details['location'] d['dealer_code'] = dealer_details['dealer_code']
d['zone']=dealer_details['zone'] d['dealer_name'] = dealer_details['dealer_name']
except: d['area'] = dealer_details['location']
pass d['zone'] = dealer_details['zone']
except:
if data: pass
return data
else: if data:
frappe.msgprint('No Data for Selected Filters.') return data
else:
frappe.msgprint('No Data for Selected Filters.')
elif filters.get('variant'):
from_date=filters['from_date'] elif filters.get('variant'):
to_date=filters['to_date'] from_date = filters['from_date']
variantfilter=filters['variant'] to_date = filters['to_date']
variantfilter=variantfilter.split(".") variantfilter = filters['variant']
data = frappe.db.sql("""SELECT date as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id, variantfilter = variantfilter.split(".")
data = frappe.db.sql("""SELECT date as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id,
procedure_id, steps_id, count(*) as count, user_id, language, procedure_id, steps_id, count(*) as count, user_id, language,
login_name,concat(first_name,' ',last_name) as user_name login_name,concat(first_name,' ',last_name) as user_name
FROM `tabModel Usage` mu left join `tabApp Users` au on mu.user_id = au.user_id FROM `tabModel Usage` mu left join `tabApp Users` au on mu.user_id = au.user_id
@ -99,54 +101,70 @@ def get_data(filters):
order by module_id,vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,language; order by module_id,vehicle_id, variant_id, variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,language;
;""".format(current_db_name, variantfilter[0], variantfilter[1], from_date, to_date), as_dict=1) ;""".format(current_db_name, variantfilter[0], variantfilter[1], from_date, to_date), as_dict=1)
for d in data: for d in data:
if d['user_id']: if d['user_id']:
try: try:
dealer_info=frappe.db.sql("""SELECT dealer FROM {0}.`tabApp Users` where user_id='{1}';""".format(current_db_name, d['user_id']), as_dict=1) dealer_info = frappe.db.sql("""SELECT dealer FROM {0}.`tabApp Users` where user_id='{1}';""".format(
dealer_info=dealer_info[-1]['dealer'] current_db_name, d['user_id']), as_dict=1)
dealer_details=frappe.db.sql("""SELECT dealer_name,dealer_code,area as location,zone FROM {0}.`tabApp Dealer` dealer_info = dealer_info[-1]['dealer']
dealer_details = frappe.db.sql("""SELECT dealer_name,dealer_code,area as location,zone FROM {0}.`tabApp Dealer`
where name='{1}';""".format(current_db_name, dealer_info), as_dict=1) where name='{1}';""".format(current_db_name, dealer_info), as_dict=1)
dealer_details=dealer_details[-1] dealer_details = dealer_details[-1]
d['dealer_code']=dealer_details['dealer_code'] d['dealer_code'] = dealer_details['dealer_code']
d['dealer_name']=dealer_details['dealer_name'] d['dealer_name'] = dealer_details['dealer_name']
d['area']=dealer_details['location'] d['area'] = dealer_details['location']
d['zone']=dealer_details['zone'] d['zone'] = dealer_details['zone']
except: except:
pass pass
if data: if data:
return data return data
else: else:
frappe.msgprint('No Data for Selected Filters.') frappe.msgprint('No Data for Selected Filters.')
def get_columns(): def get_columns():
columns = [ columns = [
{"label": _("<b>Date</b>"), "fieldname": "date", "fieldtype": "Date", "width": 150}, {"label": _("<b>Date</b>"), "fieldname": "date",
# {"label": _("<b>User ID</b>"), "fieldname": "login_name", "fieldtype": "Data", "width": 125}, "fieldtype": "Date", "width": 150},
# {"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 125}, # {"label": _("<b>User ID</b>"), "fieldname": "login_name", "fieldtype": "Data", "width": 125},
{"label": _("<b>Model</b>"), "fieldname": "vehicle_id", "fieldtype": "Data", "width": 150}, # {"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 125},
{"label": _("<b>Variant Mapping</b>"), "fieldname": "variant_mapping_id", "fieldtype": "Data", "width": 150}, {"label": _("<b>Model</b>"), "fieldname": "vehicle_id",
{"label": _("<b>Variant</b>"), "fieldname": "variant_id", "fieldtype": "Data", "width": 80}, "fieldtype": "Data", "width": 150},
{"label": _("<b>Module</b>"), "fieldname": "module_id", "fieldtype": "Data", "width": 150}, {"label": _("<b>Variant Mapping</b>"), "fieldname": "variant_mapping_id",
{"label": _("<b>System</b>"), "fieldname": "system_id", "fieldtype": "Data", "width": 150}, "fieldtype": "Data", "width": 150},
{"label": _("<b>Sub System</b>"), "fieldname": "sub_system_id", "fieldtype": "Data", "width": 150}, {"label": _("<b>Variant</b>"), "fieldname": "variant_id",
{"label": _("<b>Procedure</b>"), "fieldname": "procedure_id", "fieldtype": "Data", "width": 150}, "fieldtype": "Data", "width": 80},
{"label": _("<b>Steps</b>"), "fieldname": "steps_id", "fieldtype": "Data", "width": 150}, {"label": _("<b>Module</b>"), "fieldname": "module_id",
{"label": _("<b>Language</b>"), "fieldname": "language", "fieldtype": "Data", "width": 80}, "fieldtype": "Data", "width": 150},
{"label": _("<b>Count</b>"), "fieldname": "count", "fieldtype": "Data", "width": 80}, {"label": _("<b>System</b>"), "fieldname": "system_id",
"fieldtype": "Data", "width": 150},
# {"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 150}, {"label": _("<b>Sub System</b>"), "fieldname": "sub_system_id",
# {"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 150}, "fieldtype": "Data", "width": 150},
# {"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 150}, {"label": _("<b>Procedure</b>"), "fieldname": "procedure_id",
# {"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype": "Data", "width": 150}, "fieldtype": "Data", "width": 150},
{"label": _("<b>Device</b>"), "fieldname": "device_id", "fieldtype": "Data", "width": 150}, {"label": _("<b>Steps</b>"), "fieldname": "steps_id",
{"label": _("<b>Device Type</b>"), "fieldname": "device_type", "fieldtype": "Data", "width": 150} "fieldtype": "Data", "width": 150},
] {"label": _("<b>Language</b>"), "fieldname": "language",
return columns "fieldtype": "Data", "width": 80},
{"label": _("<b>Count</b>"), "fieldname": "count",
"fieldtype": "Data", "width": 80},
# {"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype": "Data", "width": 150},
{"label": _("<b>Device</b>"), "fieldname": "device_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Device Type</b>"), "fieldname": "device_type",
"fieldtype": "Data", "width": 150}
]
return columns
@frappe.whitelist() @frappe.whitelist()
def variant(doctype,txt,searchfield,start,page_len,filters): def variant(doctype, txt, searchfield, start, page_len, filters):
model = filters.get('name') model = filters.get('name')
variant = frappe.db.sql("""select name from `tabVariant` where name like %s""",model+'%',as_list=True) variant = frappe.db.sql(
return variant """select name from `tabVariant` where name like %s""", model+'%', as_list=True)
return variant

Loading…
Cancel
Save