comparison collect_issues.py @ 25:7161ce4e7ab1

The web-based display is dynamically generated. * All graphs are passed in one object. All graphs are passed in one object. The graphs are generated iteratiev and assigned a color. * roundup_cc.py can count how many issues are in which state.
author Magnus Schieder <mschieder@intevation.de>
date Mon, 12 Nov 2018 18:03:26 +0100
parents 3bb3d9a9f1b7
children 761ee2351f58
comparison
equal deleted inserted replaced
24:89469aa41fe1 25:7161ce4e7ab1
21 import io 21 import io
22 import sqlite3 as db 22 import sqlite3 as db
23 import os 23 import os
24 24
25 25
26 CHECK_ROUNDUP_ORDER = "priority?@action=export_csv&@columns=id,order" 26 # Getting all priority in their order.
27 CHECK_ROUNDUP_ORDER_PRIO = "priority?@action=export_csv&@columns=id,order"
28 # Getting all statuses in their order.
29 CHECK_ROUNDUP_ORDER_STATUS = "status?@action=export_csv&@columns=id,order"
30 # Getting keywords and their ids.
27 CHECK_KEYWORD_ORDER = "keyword?@action=export_csv&@columns=id,name" 31 CHECK_KEYWORD_ORDER = "keyword?@action=export_csv&@columns=id,name"
32 # Getting states and their ids.
28 CHECK_ROUNDUP_SEARCH_VALUES = "status?@action=export_csv&@columns=id,name&@filter=open&open=1" 33 CHECK_ROUNDUP_SEARCH_VALUES = "status?@action=export_csv&@columns=id,name&@filter=open&open=1"
29 SEARCH_ROUNDUP = "issue?@action=export_csv&@columns=priority&@filter=status,keyword&@pagesize=500&@startwith=0&status={search_values}&keyword={keyword_values}" 34 # Getting the priority of each issue with the filter status and keywords
35 SEARCH_ROUNDUP_PRIO = "issue?@action=export_csv&@columns=priority&@filter=status,keyword&@pagesize=500&@startwith=0&status={search_values}&keyword={keyword_values}"
36 # Getting the status of each issue with the filter keywords
37 SEARCH_ROUNDUP_STATUS = "issue?@action=export_csv&@columns=status&@filter=keyword&@pagesize=500&@startwith=0&keyword={keyword_values}"
30 38
31 39
32 def connect_to_server(params, baseurl): 40 def connect_to_server(params, baseurl):
33 enc_data = urllib.parse.urlencode(params).encode() 41 enc_data = urllib.parse.urlencode(params).encode()
34 cj = http.cookiejar.CookieJar() 42 cj = http.cookiejar.CookieJar()
80 88
81 return ",".join(keywords_ids) 89 return ",".join(keywords_ids)
82 90
83 def get_status_ids(opener, baseurl, status): 91 def get_status_ids(opener, baseurl, status):
84 92
85 status_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_SEARCH_VALUES)
86
87 if status == [""]: 93 if status == [""]:
88 return "" 94 return ""
95
96 status_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_SEARCH_VALUES)
89 97
90 status_dict = {} 98 status_dict = {}
91 for x in status_csv: 99 for x in status_csv:
92 status_dict[x["name"]] = x["id"] 100 status_dict[x["name"]] = x["id"]
93 101
111 #convert the csv-dict reader to real dict 119 #convert the csv-dict reader to real dict
112 for row in orders_csv: 120 for row in orders_csv:
113 order_dict[row["id"]] = int(float(row["order"])) # int(float()) because the order-value is indeed "1.0, 2.0" etc 121 order_dict[row["id"]] = int(float(row["order"])) # int(float()) because the order-value is indeed "1.0, 2.0" etc
114 122
115 for issue in issue_csv: 123 for issue in issue_csv:
116 priority = issue["priority"] 124 priority = issue[issue_csv.fieldnames[0]]
117 125
118 if priority.isdigit() == True : 126 if priority.isdigit() == True :
119 quantities[order_dict[priority] -1 ] += 1 127 quantities[order_dict[priority] -1 ] += 1
120 else: # no priority set 128 else: # no priority set
121 quantities[-1] += 1 129 quantities[-1] += 1
122 130
123 # print("quantities : " + str(quantities)) 131 # print("quantities : " + str(quantities))
124 132
125 return quantities 133 return quantities
126 134
127 135
128 def save_issues_to_db(quantities, database_file, sql_create_db, sql_insert_in_db): 136 def save_issues_to_db(quantities, database_file, sql_create_db, sql_insert_in_db):
145 cur.close() 153 cur.close()
146 if con: 154 if con:
147 con.close() 155 con.close()
148 156
149 157
150 def save_stats_in_db(login_parmeters, baseurl, db_file, columns, sql_create_db, sql_insert_in_db, keywords, status, include_no_prio=False): 158 def save_stats_in_db(search, login_parmeters, baseurl, db_file, columns, sql_create_db, sql_insert_in_db, keywords, status, include_no_prio=False):
151 try: 159 try:
152 160
153 opener = connect_to_server(login_parmeters, baseurl) 161 opener = connect_to_server(login_parmeters, baseurl)
154 162
155 order_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_ORDER)
156
157 keywords_ids_url = get_keyword_ids(opener, baseurl, keywords) 163 keywords_ids_url = get_keyword_ids(opener, baseurl, keywords)
158 164
159 status_ids_url = get_status_ids(opener, baseurl, status) 165 if search == "prio":
160 formated_search_url = SEARCH_ROUNDUP.format(search_values=status_ids_url, keyword_values=keywords_ids_url) 166 order_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_ORDER_PRIO)
167 status_ids_url = get_status_ids(opener, baseurl, status)
168 formated_search_url = SEARCH_ROUNDUP_PRIO.format(search_values=status_ids_url, keyword_values=keywords_ids_url)
169 elif search == "status":
170 order_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_ORDER_STATUS)
171 formated_search_url = SEARCH_ROUNDUP_STATUS.format(keyword_values=keywords_ids_url)
172 else:
173 print("Incorrect search parameter. (prio, status)")
161 174
162 current_issues_csv = get_csv_from_server(opener, baseurl, formated_search_url) 175 current_issues_csv = get_csv_from_server(opener, baseurl, formated_search_url)
163 176
164 opener.close() 177 opener.close()
165 178
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)