Commit 5843a38b authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Refactor Ticket report

Use Grade System for classify the quality of the service
parent 9925fe9e
slo_dict = context.ERP5Site_getServiceLevelObjectiveDict()
if slo not in slo_dict:
raise ValueError("Service Level Objective not found!")
grade_dict = slo_dict[slo]
for grade, threshold in grade_dict.iteritems():
if value <= threshold:
return "%s (%s)" % (grade, value)
return "F (%s)" % value
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>slo, value</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getServiceLevelObjectGrade</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
grade = context.Base_getServiceLevelObjectGrade(slo, value)
return grade
# Report seems not able to render HTML
color_dict = {
"A": "lightgreen",
"B": "green",
"C": "blue",
"D": "orange",
"E": "red",
"F": "red",
}
for g, color in color_dict.iteritems():
if grade.startswith(g):
return "<font color='%s'>%s</font>" % (color, grade)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>slo, value</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getServiceLevelObjectGradeAsHTML</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
slo_dict = {
"created_per_day" : {
"A": 0,
"B": 5,
"C": 10,
"D": 15,
"E": 30
},
"closed_per_day": {
"A": 0,
"B": 2,
"C": 5,
"D": 10,
"E": 15
},
"remaining_ticket": {
"A": 5,
"B": 10,
"C": 15,
"D": 20,
"E": 30,
},
"monitoring_instance_ticket_per_month": {
"A": 0,
"B": 2,
"C": 5,
"D": 10,
"E": 15
},
"avg_created_per_day": {
"A": 0,
"B": 3,
"C": 6,
"D": 9,
"E": 12
},
"monitoring_eta_resolution": {
"A": 0,
"B": 1,
"C": 2,
"D": 3,
"E": 4,
},
"user_instance_ticket_per_month": {
"A": 0,
"B": 2,
"C": 5,
"D": 7,
"E": 10
},
"user_avg_created_per_day": {
"A": 0.06,
"B": 0.15,
"C": 0.5,
"D": 0.75,
"E": 0.8
},
"user_eta_response": {
"A": 0,
"B": 1,
"C": 2,
"D": 3,
"E": 4
},
"user_eta_resolution": {
"A": 2,
"B": 3,
"C": 4,
"D": 6,
"E": 8
}
}
return slo_dict
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getServiceLevelObjectiveDict</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
note_weight = {
'A' : 0,
'B' : 1,
'C' : 3,
'D' : 5,
'E' : 7,
'F' : 9
}
note_label = {
'A' : "GOOD",
'B' : "OK",
'C' : "WORK REQUIRED",
'D' : "BAD",
'E' : "REALLY BAD",
'F' : "UNUSABLE"
}
grade_list= [
["closed_per_day", dict(month_avg=True, delta_closed_amount=True)],
["closed_per_day", dict(week_avg=True, delta_closed_amount=True)],
["closed_per_day", dict(delta=0, delta_closed_amount=True)],
["closed_per_day", dict(delta=-1, delta_closed_amount=True)],
["avg_created_per_day", dict(week_avg=True)],
["avg_created_per_day", dict(month_avg=True)],
["created_per_day", dict(delta=0)],
["created_per_day", dict(delta=-1)],
]
grade_result_list = []
for key, params in grade_list:
grade_result_list.append(
context.Base_getServiceLevelObjectGrade(key,
context.SupportRequestModule_countTicket(**params)))
remaining_grade = context.Base_getServiceLevelObjectGrade("remaining_ticket",
context.portal_catalog.countResults(portal_type="Support Request", simulation_state=["validated", "suspended"])[0][0])
# Remaining Grade has the double of the weight
grade_result_list.append(remaining_grade)
grade_result_list.append(remaining_grade)
result = 0
for grade_result in grade_result_list:
result += note_weight[grade_result.split(" ")[0]]
for n, value in note_weight.iteritems():
if result <= len(grade_result_list)*value:
return "%s (%s)" % (note_label[n], n)
return "F (UNUSABLE)"
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SupportRequestModule_calculateGeneralGrade</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from DateTime import DateTime
portal = context.getPortalObject()
# Hardcode the Date Range here
if month_avg:
today = DateTime() - 30
creation_date = ">=%s/%02d/%02d" % (today.year(), today.month(), today.day())
ratio = 30
elif week_avg:
today = DateTime() - 7
creation_date = ">=%s/%02d/%02d" % (today.year(), today.month(), today.day())
ratio = 7
else:
ratio = 1
today = DateTime() + delta
creation_date = "%s/%02d/%02d" % (today.year(), today.month(), today.day())
def getSupportRequestList(creation_date):
return portal.portal_catalog(
portal_type="Support Request",
creation_date=creation_date)
def getClosedSupportRequestList(modifiction_date):
return portal.portal_catalog(
portal_type="Support Request",
simulation_state="invalidated",
modification_date=modifiction_date)
if delta_closed_amount:
return (len(getSupportRequestList(creation_date)) - len(getClosedSupportRequestList(creation_date)))/ratio
return len(getSupportRequestList(creation_date))/ratio
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>delta=0, month_avg=0, week_avg=False, delta_closed_amount=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SupportRequestModule_countTicket</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -4,14 +4,8 @@ result=[] ...@@ -4,14 +4,8 @@ result=[]
result.append(ReportSection( result.append(ReportSection(
path=context.getPhysicalPath(), path=context.getPhysicalPath(),
level=2, level=1,
title=context.Base_translateString('Current State'), title=context.Base_translateString('Service Grade'),
form_id="SupportRequestModule_viewTicketCurrentStatus")) form_id="SupportRequestModule_viewTicketCurrentStatus"))
result.append(ReportSection(
path=context.getPhysicalPath(),
level=2,
title=context.Base_translateString('Support Request Montly Activity'),
form_id="SupportRequestModule_viewTicketActivity"))
return result return result
...@@ -59,11 +59,11 @@ ...@@ -59,11 +59,11 @@
<key> <string>group_list</string> </key> <key> <string>group_list</string> </key>
<value> <value>
<list> <list>
<string>bottom</string>
<string>left (User Tickets)</string> <string>left (User Tickets)</string>
<string>right</string> <string>right</string>
<string>right (Monitor)</string> <string>right (Monitor)</string>
<string>center</string> <string>center</string>
<string>bottom</string>
<string>hidden</string> <string>hidden</string>
</list> </list>
</value> </value>
...@@ -75,7 +75,9 @@ ...@@ -75,7 +75,9 @@
<item> <item>
<key> <string>bottom</string> </key> <key> <string>bottom</string> </key>
<value> <value>
<list/> <list>
<string>your_comment</string>
</list>
</value> </value>
</item> </item>
<item> <item>
...@@ -97,6 +99,7 @@ ...@@ -97,6 +99,7 @@
<value> <value>
<list> <list>
<string>your_at_date</string> <string>your_at_date</string>
<string>your_grade</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -141,7 +144,7 @@ ...@@ -141,7 +144,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>SlapOS Ticket Activity Report</string> </value> <value> <string>Ticket Grade</string> </value>
</item> </item>
<item> <item>
<key> <string>unicode_mode</string> </key> <key> <string>unicode_mode</string> </key>
......
...@@ -61,7 +61,6 @@ ...@@ -61,7 +61,6 @@
<list> <list>
<string>left (User Tickets)</string> <string>left (User Tickets)</string>
<string>right</string> <string>right</string>
<string>right (Monitor)</string>
<string>center</string> <string>center</string>
<string>bottom</string> <string>bottom</string>
<string>hidden</string> <string>hidden</string>
...@@ -94,9 +93,14 @@ ...@@ -94,9 +93,14 @@
<key> <string>left (User Tickets)</string> </key> <key> <string>left (User Tickets)</string> </key>
<value> <value>
<list> <list>
<string>your_open_ticket_total</string> <string>your_remaining_ticket_grade</string>
<string>your_created_today_grade</string>
<string>your_created_yesterday_grade</string>
<string>your_created_avg_week_grade</string>
<string>your_created_avg_month_grade</string>
<string>your_suspended_ticket_total</string> <string>your_suspended_ticket_total</string>
<string>your_closed_ticket_total</string> <string>your_closed_ticket_total</string>
<string>your_open_ticket_total</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -104,18 +108,16 @@ ...@@ -104,18 +108,16 @@
<key> <string>right</string> </key> <key> <string>right</string> </key>
<value> <value>
<list> <list>
<string>your_closed_today_grade</string>
<string>your_closed_yesterday_grade</string>
<string>your_closed_avg_month_grade</string>
<string>your_closed_avg_week_grade</string>
<string>your_open_monitor_ticket_total</string> <string>your_open_monitor_ticket_total</string>
<string>your_suspended_monitor_ticket_total</string> <string>your_suspended_monitor_ticket_total</string>
<string>your_closed_monitor_ticket_total</string> <string>your_closed_monitor_ticket_total</string>
</list> </list>
</value> </value>
</item> </item>
<item>
<key> <string>right (Monitor)</string> </key>
<value>
<list/>
</value>
</item>
</dictionary> </dictionary>
</value> </value>
</item> </item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment