Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save demonstrations and video snapshots to firebase #36

Open
kavidey opened this issue Oct 6, 2021 · 2 comments
Open

Save demonstrations and video snapshots to firebase #36

kavidey opened this issue Oct 6, 2021 · 2 comments

Comments

@kavidey
Copy link
Collaborator

kavidey commented Oct 6, 2021

We need to be able to save snapshots (or even entire videos) as part of the initial demonstration. One option is to base64 encode the image and save that in firebase, we might also want to look a local way to save the data (the interface already has WebRTC video saving setup)

@kavidey kavidey changed the title Save video snapshots to firebase Save demonstrations and video snapshots to firebase Nov 10, 2021
@kavidey
Copy link
Collaborator Author

kavidey commented Nov 10, 2021

I'm currently working on implementing the new data storage format in firebase. It is based on how we saved data for the cursor-based teleoperation project: https://github.com/mayacakmak/se2/blob/master/scripts/database.js

The system is categorized by user, session, demonstration, and action

  • Users: The anonymous users
  • Session: One time one user logs into the interface
  • Demonstration: A set of actions from taken by a user to demonstrate a specific task
  • Action: A single action or state change that takes place as part of a demonstration
// Users contains only meta info about each user such as session start time
//  and any other information we need to save about them
// This is stored under each user's unique ID
"users": {
  "u1": {
    "s1": {
      "date": "Wed Jun 10 2020",
      "time": "11:45:13 GMT-0700 (Pacific Daylight Time)",
      "timestamp": 1591814713656
      "demonstrations": ["d1", "d2", ...]
    }
  },
  "u2": { ... },
  "u3": { ... }
},
// Demonstrations and actions are separated from users
// so we can still query individual events easily
"demonstrations": {
  "d1": {
    "a1": {
      "date": "Thu Jun 27 2019",
      "eventName": "GripperOpen",
      "eventInfo": "medium",
      "time": "16:40:27 GMT-0700 (Pacific Daylight Time)",
      "timeStamp": 1561678827981
    },
    "a2": { ... },
    "a3": { ... }
  },
  "d2": { ... },
  "d3": { ... }
}

Firebase tends to work best with flatter data structures because it allows querying of individual demonstrations without needing to download all of them. We ran into some issues on the previous project where too much depth resulted in massive files that were difficult to download.

Note: This is technically a bit insecure since any user who is logged in has permission to write to all of /demonstrations, but we should be able to remove read permissions since they only need to write. Then, a nefarious user would have no way to figure out what demonstration id to write to (they are long randomly generated strings)

@kavidey
Copy link
Collaborator Author

kavidey commented Dec 12, 2021

Image snapshotting is functional, but I'm not sure if we want to use it. One frame from one camera is around 20kB. So 20 kB x 3 cameras x 1 image per second x 1 mins is 3.6 megabytes per minute or 216 megabytes per hour.

That is a fair amount of data to save to firebase realtime, and even with the flattened data structure would likely slow it down (especially if we do lots of demonstrations). The free firebase plan only allows 1 gb of storage, so we would probably fill that up pretty quickly.

If we only save data when a certain action is triggered (ex start/stop demonstration) or only save on camera, it would help, but it may be better to think about alternative methods. We could look at saving the demonstrations locally, or save it to the firestore database instead of the firebase realtime database (this would probably require paying a bit extra).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant