aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-12-29 22:16:17 +1100
committerTerry Truong <terry06890@gmail.com>2022-12-29 22:16:17 +1100
commita3c5a73fae39de296cd05bde1a6853e20f84305a (patch)
tree36c701f06a50d9d0b478606cb7b43b761650771c
parent29f17375c623ff18cd8f2d5d828ebc462d01f617 (diff)
Make server send error for breaking unit-count limit
-rwxr-xr-xbackend/histplorer.py11
-rw-r--r--src/App.vue24
-rw-r--r--src/components/TimeLine.vue16
-rw-r--r--src/lib.ts2
4 files changed, 29 insertions, 24 deletions
diff --git a/backend/histplorer.py b/backend/histplorer.py
index edd675f..d397c17 100755
--- a/backend/histplorer.py
+++ b/backend/histplorer.py
@@ -27,6 +27,7 @@ from hist_data.cal import gregorianToJdn, HistDate, dbDateToHistDate, dateToUnit
DB_FILE = 'hist_data/data.db'
MAX_REQ_EVENTS = 500
+MAX_REQ_UNIT_COUNTS = MAX_REQ_EVENTS
DEFAULT_REQ_EVENTS = 20
MAX_REQ_SUGGS = 50
DEFAULT_REQ_SUGGS = 5
@@ -65,9 +66,9 @@ class Event:
return str(self.__dict__)
class EventResponse:
""" Used when responding to type=events requests """
- def __init__(self, events: list[Event], unitCounts: dict[int, int]):
+ def __init__(self, events: list[Event], unitCounts: dict[int, int] | None):
self.events = events
- self.unitCounts = unitCounts
+ self.unitCounts = unitCounts # None indicates exceeding MAX_REQ_UNIT_COUNTS
# Used in unit testing
def __eq__(self, other):
return isinstance(other, EventResponse) and \
@@ -273,7 +274,7 @@ def eventEntryToResults(
#
return Event(eventId, title, newDates[0], newDates[1], newDates[2], newDates[3], ctg, imageId, pop)
def lookupUnitCounts(
- start: HistDate | None, end: HistDate | None, scale: int, dbCur: sqlite3.Cursor) -> dict[int, int]:
+ start: HistDate | None, end: HistDate | None, scale: int, dbCur: sqlite3.Cursor) -> dict[int, int] | None:
# Build query
query = 'SELECT unit, count FROM dist WHERE scale = ?'
params = [scale]
@@ -283,12 +284,12 @@ def lookupUnitCounts(
if end:
query += ' AND unit <= ?'
params.append(dateToUnit(end, scale))
- query += ' ORDER BY unit ASC LIMIT ' + str(MAX_REQ_EVENTS)
+ query += ' ORDER BY unit ASC LIMIT ' + str(MAX_REQ_UNIT_COUNTS + 1)
# Get results
unitCounts: dict[int, int] = {}
for unit, count in dbCur.execute(query, params):
unitCounts[unit] = count
- return unitCounts
+ return unitCounts if len(unitCounts) <= MAX_REQ_UNIT_COUNTS else None
# For type=info
def handleInfoReq(params: dict[str, str], dbCur: sqlite3.Cursor):
diff --git a/src/App.vue b/src/App.vue
index ddc434f..31be46d 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -141,7 +141,7 @@ function reduceEvents(){
idToEvent = eventsToKeep;
}
// For getting events from server
-const EVENT_REQ_LIMIT = 500;
+const EVENT_REQ_LIMIT = 300;
let queriedRanges: DateRangeTree[] = SCALES.map(() => new DateRangeTree());
// For each scale, holds date ranges for which data has already been queried fromm the server
let pendingReq = false; // Used to serialise event-req handling
@@ -170,27 +170,31 @@ async function onEventDisplay(
}
queriedRanges[scaleIdx].add([firstDate, lastDate]);
// Collect events
- let added = false;
+ let eventAdded = false;
for (let eventObj of responseObj.events){
let event = jsonToHistEvent(eventObj);
let success = eventTree.value.insert(event);
if (success){
- added = true;
+ eventAdded = true;
idToEvent.set(event.id, event);
}
}
// Collect unit counts
const unitCounts = responseObj.unitCounts;
- for (let [unitStr, count] of Object.entries(unitCounts)){
- let unit = parseInt(unitStr)
- if (isNaN(unit)){
- console.log('ERROR: Invalid non-integer unit value in server response');
- break;
+ if (unitCounts == null){
+ console.log('WARNING: Exceeded unit-count limit for server query');
+ } else {
+ for (let [unitStr, count] of Object.entries(unitCounts)){
+ let unit = parseInt(unitStr)
+ if (isNaN(unit)){
+ console.log('WARNING: Invalid non-integer unit value in server response');
+ break;
+ }
+ unitCountMaps.value[scaleIdx].set(unit, count)
}
- unitCountMaps.value[scaleIdx].set(unit, count)
}
// Notify components if new events were added
- if (added){
+ if (eventAdded){
eventTree.value = rbtree_shallow_copy(eventTree.value); // Note: triggerRef(eventTree) does not work here
}
// Check memory limit
diff --git a/src/components/TimeLine.vue b/src/components/TimeLine.vue
index 7b89194..d68cff0 100644
--- a/src/components/TimeLine.vue
+++ b/src/components/TimeLine.vue
@@ -15,6 +15,14 @@
<stop offset="95%" stop-color="gold"/>
</linearGradient>
</defs>
+ <!-- Event lines (dashed line indicates imprecise start date) -->
+ <line v-for="id in eventLines.keys()" :key="id"
+ x1="0" y1="0" :x2="eventLines.get(id)![2]" y2="0.01"
+ stroke="url('#eventLineGradient')" stroke-width="1px"
+ :stroke-dasharray="getEventPrecision(idToEvent.get(id)!) <= minorScale ? '' : '16,4'"
+ :style="eventLineStyles(id)" class="animate-fadein"/>
+ <!-- Note: With a fully vertical or horizontal line, nothing gets displayed -->
+ <!-- Note: Can't use :x2="1" with scaling in :style="", as it makes dashed-lines non-uniform -->
<!-- Main line (unit horizontal line that gets transformed, with extra length to avoid gaps when panning) -->
<line :stroke="store.color.alt" stroke-width="2px" x1="-1" y1="0" x2="2" y2="0" :style="mainlineStyles"/>
<!-- Tick markers -->
@@ -36,14 +44,6 @@
:fill="store.color.textDark" :style="tickLabelStyles(tick)" class="text-sm animate-fadein">
{{tick.date.toDisplayString()}}
</text>
- <!-- Event lines (dashed line indicates imprecise start date) -->
- <line v-for="id in eventLines.keys()" :key="id"
- x1="0" y1="0" :x2="eventLines.get(id)![2]" y2="0.01"
- stroke="url('#eventLineGradient')" stroke-width="1px"
- :stroke-dasharray="getEventPrecision(idToEvent.get(id)!) <= minorScale ? '' : '16,4'"
- :style="eventLineStyles(id)" class="animate-fadein"/>
- <!-- Note: With a fully vertical or horizontal line, nothing gets displayed -->
- <!-- Note: Can't use :x2="1" with scaling in :style="", as it makes dashed-lines non-uniform -->
</svg>
<!-- Events -->
<div v-for="id in idToPos.keys()" :key="id" class="absolute animate-fadein z-20" :style="eventStyles(id)">
diff --git a/src/lib.ts b/src/lib.ts
index a060fad..cd177ff 100644
--- a/src/lib.ts
+++ b/src/lib.ts
@@ -308,7 +308,7 @@ export type HistEventJson = {
}
export type EventResponseJson = {
events: HistEventJson[],
- unitCounts: {[x: number]: number},
+ unitCounts: {[x: number]: number} | null,
}
export function jsonToHistDate(json: HistDateJson){
if (json.gcal == null){