Compare commits
2 Commits
b13cdb9c09
...
5c956a6680
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c956a6680 | ||
|
|
8cf9fc4513 |
BIN
SEN presentation.pdf
Normal file
BIN
SEN presentation.pdf
Normal file
Binary file not shown.
BIN
data.sqlite3
BIN
data.sqlite3
Binary file not shown.
@@ -31,7 +31,7 @@ cur.execute("PRAGMA foreign_keys = ON;")
|
|||||||
categories = """CREATE TABLE IF NOT EXISTS categories(id INTEGER PRIMARY KEY AUTOINCREMENT , name TEXT)"""
|
categories = """CREATE TABLE IF NOT EXISTS categories(id INTEGER PRIMARY KEY AUTOINCREMENT , name TEXT)"""
|
||||||
subcat = """CREATE TABLE IF NOT EXISTS subcat(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, cat_id INTEGER, FOREIGN KEY(cat_id) REFERENCES categories(id))"""
|
subcat = """CREATE TABLE IF NOT EXISTS subcat(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, cat_id INTEGER, FOREIGN KEY(cat_id) REFERENCES categories(id))"""
|
||||||
location = """CREATE TABLE IF NOT EXISTS location(id INTEGER PRIMARY KEY AUTOINCREMENT , subdiv TEXT, LGA TEXT)"""
|
location = """CREATE TABLE IF NOT EXISTS location(id INTEGER PRIMARY KEY AUTOINCREMENT , subdiv TEXT, LGA TEXT)"""
|
||||||
stat = """CREATE TABLE IF NOT EXISTS statistics(id INTEGER PRIMARY KEY AUTOINCREMENT , category_id INTEGER, subcat_id INTEGER DEFAULT 0, location_id INTEGER, month TEXT NOT NULL, count TEXT NOT NULL,FOREIGN KEY(category_id) REFERENCES categories(id), FOREIGN KEY(subcat_id) REFERENCES subcat(id), FOREIGN KEY(location_id) REFERENCES location(id))"""
|
stat = """CREATE TABLE IF NOT EXISTS statistics(id INTEGER PRIMARY KEY AUTOINCREMENT , category_id INTEGER, subcat_id INTEGER DEFAULT 0, location_id INTEGER, count TEXT NOT NULL,FOREIGN KEY(category_id) REFERENCES categories(id), FOREIGN KEY(subcat_id) REFERENCES subcat(id), FOREIGN KEY(location_id) REFERENCES location(id))"""
|
||||||
cur.execute(categories)
|
cur.execute(categories)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
cur.execute(subcat)
|
cur.execute(subcat)
|
||||||
@@ -44,7 +44,7 @@ conn.commit()
|
|||||||
categories_ins = """INSERT INTO categories VALUES(NULL, :category)"""
|
categories_ins = """INSERT INTO categories VALUES(NULL, :category)"""
|
||||||
subcat_ins = """INSERT INTO subcat VALUES(NULL, :name, :catid)"""
|
subcat_ins = """INSERT INTO subcat VALUES(NULL, :name, :catid)"""
|
||||||
location_ins = """INSERT INTO location VALUES(NULL, :subdiv, :lga)"""
|
location_ins = """INSERT INTO location VALUES(NULL, :subdiv, :lga)"""
|
||||||
stat_ins = """INSERT INTO statistics VALUES(NULL,:cat_id,:subcat_id,:loc_id,:mnth,:cnt)"""
|
stat_ins = """INSERT INTO statistics VALUES(NULL,:cat_id,:subcat_id,:loc_id,:cnt)"""
|
||||||
|
|
||||||
for i in range(len(cat)):
|
for i in range(len(cat)):
|
||||||
cur.execute(categories_ins, {"category": cat[i]})
|
cur.execute(categories_ins, {"category": cat[i]})
|
||||||
@@ -79,7 +79,7 @@ for i in range(len(biglst)):
|
|||||||
dat_lst.append(biglst[i][j])
|
dat_lst.append(biglst[i][j])
|
||||||
|
|
||||||
|
|
||||||
init_lst.append({"cat_id": catid, "subcat_id": subcatid, "loc_id": locid, "mnth": pandas.to_datetime(str(init_date+numpy.timedelta64(j-4, 'M'))).strftime('%Y.%m'),"cnt":json.dumps(dat_lst)})
|
init_lst.append({"cat_id": catid, "subcat_id": subcatid, "loc_id": locid,"cnt":json.dumps(dat_lst)})
|
||||||
print(i)
|
print(i)
|
||||||
cur.executemany(stat_ins, init_lst)
|
cur.executemany(stat_ins, init_lst)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|||||||
14
index.html
14
index.html
@@ -1,21 +1,23 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Crime Statistics</title>
|
<title>NSW Crime Statistics</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<!-- dependencies -->
|
<!-- Bootstrap -->
|
||||||
<link href="https://cdn.jsdelivr.net/npm/@coreui/coreui@5.2.0/dist/css/themes/bootstrap/bootstrap.min.css" rel="stylesheet" integrity="sha384-nQQlHXZO4YmST3YDqk/JU3f1t2D58a/nPd1QbiLecouKn68glzRym4BlOxlr5Rrg" crossorigin="anonymous">
|
<link href="https://cdn.jsdelivr.net/npm/@coreui/coreui@5.2.0/dist/css/themes/bootstrap/bootstrap.min.css" rel="stylesheet" integrity="sha384-nQQlHXZO4YmST3YDqk/JU3f1t2D58a/nPd1QbiLecouKn68glzRym4BlOxlr5Rrg" crossorigin="anonymous">
|
||||||
</head>
|
</head>
|
||||||
<body style="background-color: #ffffff;">
|
<body style="background-color: #ffffff;">
|
||||||
|
<!--Bootstrap-->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script>
|
||||||
<!--chartjs-->
|
<!--chartjs-->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
<!--handlebars-->
|
<!--handlebars-->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>
|
||||||
<!-- bootstrap--> <!-- SQL -->
|
<!--sqlite-->
|
||||||
<script src="https://12sen.dchen4.au/sqlite-js/sqlite3.js"></script>
|
<script src="https://12sen.dchen4.au/sqlite-js/sqlite3.js"></script>
|
||||||
|
<!--moment-->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/moment@2.30.1/moment.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/moment@2.30.1/moment.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
@@ -178,13 +180,13 @@
|
|||||||
|
|
||||||
<ul class="nav nav-tabs" id="myTab" role="tablist">
|
<ul class="nav nav-tabs" id="myTab" role="tablist">
|
||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item" role="presentation">
|
||||||
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Line</button>
|
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="Line" aria-selected="true">Line</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item" role="presentation">
|
||||||
<button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Pie/Bar</button>
|
<button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="Pie/Bar" aria-selected="false">Pie/Bar</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item" role="presentation">
|
||||||
<button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Table</button>
|
<button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact" type="button" role="tab" aria-controls="Table" aria-selected="false">Table</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content" id="myTabContent">
|
<div class="tab-content" id="myTabContent">
|
||||||
|
|||||||
32
index.js
32
index.js
@@ -362,10 +362,10 @@ class FilterQueue{
|
|||||||
//all array
|
//all array
|
||||||
for (var i=start_cnt;i<end_cnt;i++){
|
for (var i=start_cnt;i<end_cnt;i++){
|
||||||
var val;
|
var val;
|
||||||
val = JSON.parse(res[0][5])[i]
|
val = JSON.parse(res[0][4])[i]
|
||||||
//one array, find avg of all 1st val
|
//one array, find avg of all 1st val
|
||||||
for (var j=1;j<res.length;j++){
|
for (var j=1;j<res.length;j++){
|
||||||
val = (val+JSON.parse(res[j][5])[i])/2
|
val = (val+JSON.parse(res[j][4])[i])/2
|
||||||
}
|
}
|
||||||
res_arr.push(Math.round(val));
|
res_arr.push(Math.round(val));
|
||||||
}
|
}
|
||||||
@@ -375,9 +375,9 @@ class FilterQueue{
|
|||||||
val = 0;
|
val = 0;
|
||||||
//modify JSON.parse(res[0][5]) and initial i to control the range of the months
|
//modify JSON.parse(res[0][5]) and initial i to control the range of the months
|
||||||
for (var i=start_cnt; i<end_cnt;i++){
|
for (var i=start_cnt; i<end_cnt;i++){
|
||||||
val = JSON.parse(res[0][5])[i]
|
val = JSON.parse(res[0][4])[i]
|
||||||
for (var j=1;j<res.length;j++){
|
for (var j=1;j<res.length;j++){
|
||||||
val += JSON.parse(res[j][5])[i]
|
val += JSON.parse(res[j][4])[i]
|
||||||
}
|
}
|
||||||
val+=Math.round(val)
|
val+=Math.round(val)
|
||||||
}
|
}
|
||||||
@@ -396,7 +396,7 @@ class FilterQueue{
|
|||||||
//formulate graph object
|
//formulate graph object
|
||||||
var graph_lst = []
|
var graph_lst = []
|
||||||
for (var i=0; i<plotlst.length;i++){
|
for (var i=0; i<plotlst.length;i++){
|
||||||
graph_lst.push({"lineTension":0.3, label:"Query "+String(i+1), "data": plotlst[i], borderWidth:1})
|
graph_lst.push({"lineTension":0.3, label:"Query #"+String(i+1), "data": plotlst[i], borderWidth:1})
|
||||||
}
|
}
|
||||||
|
|
||||||
var pie_lbl = [];
|
var pie_lbl = [];
|
||||||
@@ -405,7 +405,7 @@ class FilterQueue{
|
|||||||
|
|
||||||
//why don't we generate the bg colour as well
|
//why don't we generate the bg colour as well
|
||||||
for (var i=0; i<pielst.length;i++){
|
for (var i=0; i<pielst.length;i++){
|
||||||
pie_lbl.push("Query "+String(i+1))
|
pie_lbl.push("Query #"+String(i+1))
|
||||||
pie_colour.push(random_rgba())
|
pie_colour.push(random_rgba())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,25 +660,5 @@ function init(sqlite3){
|
|||||||
global_component = new Filter(new db_handler(sqlite3));
|
global_component = new Filter(new db_handler(sqlite3));
|
||||||
chart = new Chart(new db_handler(sqlite3));
|
chart = new Chart(new db_handler(sqlite3));
|
||||||
queue_filter = new FilterQueue(new db_handler(sqlite3));
|
queue_filter = new FilterQueue(new db_handler(sqlite3));
|
||||||
|
|
||||||
Handlebars.registerHelper('range', function(start, end) {
|
|
||||||
let result = [];
|
|
||||||
for (let i = start; i < end; i++) {
|
|
||||||
result.push(i);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
|
|
||||||
Handlebars.registerHelper('maxLength', function(arrays) {
|
|
||||||
var len = Math.max(...arrays.map(array => array.length));
|
|
||||||
console.log(len);
|
|
||||||
return len;
|
|
||||||
});
|
|
||||||
|
|
||||||
Handlebars.registerHelper("setVar", function(varName, varValue, options) {
|
|
||||||
options.data.root[varName] = varValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user