hmc-whisk / jsLDA

A React based version of jsLDA with brand new features added on
Other
0 stars 0 forks source link

Timeseries page crashes application when opened after model upload #168

Closed xandaschofield closed 3 years ago

xandaschofield commented 3 years ago

I uploaded a saved model and was able to start browsing through the topic documents page, but when I turned to the timeseries page, it blanked out with the following error:

react-dom.production.min.js:209 TypeError: Reduce of empty array with no initial value
    at Array.reduce (<anonymous>)
    at LDAModel.js:1087
    at Array.forEach (<anonymous>)
    at topicTimesBinnedAverage (LDAModel.js:1086)
    at o.value (TimeSeries.js:184)
    at o.value (TimeSeries.js:93)
    at o.value (TimeSeries.js:360)
    at co (react-dom.production.min.js:212)
    at xd (react-dom.production.min.js:255)
    at t.unstable_runWithPriority (scheduler.production.min.js:19)
uo @ react-dom.production.min.js:209
react-dom.production.min.js:123 Uncaught TypeError: Reduce of empty array with no initial value
    at Array.reduce (<anonymous>)
    at LDAModel.js:1087
    at Array.forEach (<anonymous>)
    at topicTimesBinnedAverage (LDAModel.js:1086)
    at o.value (TimeSeries.js:184)
    at o.value (TimeSeries.js:93)
    at o.value (TimeSeries.js:360)
    at co (react-dom.production.min.js:212)
    at xd (react-dom.production.min.js:255)
    at t.unstable_runWithPriority (scheduler.production.min.js:19)
theobayard commented 3 years ago

This was caused by date objects being uploaded as strings instead of objects. In general, any objects in our ldaModel that aren't base classes (I don't remember the exact definition of base classes but I'm thinking anything you need to use 'new' in the declaration of) are probably going to need to be repaired after an upload. So far, the only object that falls in that category (as far as I can see) were these Date objects, but there might be more in the future. In preparation for this, I created a broader function that will be called after a file is uploaded. Right now it just calls one function that remakes the date objects, but I figure it's a good function to have for future repairs that might be needed.

Moral of the story: If you create a member object of the ldaModel that was initialized with 'new' be prepared to fix it after a model upload by adding a function to LDAModel.modelUploaded