fixed bug by adding check when array is not defined
refactored to separate charting, data processing, and socket.io from index.ejs