Skip to content

Database Interaction

Simon Gibson edited this page Sep 4, 2024 · 1 revision

VidToNerf Database Interaction Specification

Overview

VidToNerf uses MongoDB as its database. The database is named nerfdb and contains the following collections:

  1. scenes
  2. users
  3. queues

Collection Structures

1. Scenes Collection

The scenes collection stores information about each scene processed by the system.

Document Structure:

{
  _id: ObjectId,
  video: {
    file_path: String,
    width: Number,
    height: Number,
    fps: Number,
    duration: Number,
    frame_count: Number
  },
  sfm: {
    intrinsic_matrix: [[Number]],
    frames: [
      {
        file_path: String,
        extrinsic_matrix: [[Number]]
      }
    ],
    white_background: Boolean
  },
  config: {
    sfm_training_config: {
      // Add fields as needed
    },
    nerf_training_config: {
      training_mode: String,
      output_types: [String],
      save_iterations: [Number],
      total_iterations: Number
    }
  },
  nerf: {
    model_file_paths: {
      [iteration: Number]: String
    },
    splat_cloud_file_paths: {
      [iteration: Number]: String
    },
    point_cloud_file_paths: {
      [iteration: Number]: String
    },
    video_file_paths: {
      [iteration: Number]: String
    },
    flag: Number
  },
  status: Number,
  name: String
}

2. Users Collection

The users collection stores user information.

Document Structure:

{
  _id: ObjectId,
  username: String,
  encrypted_password: String,
  scene_ids: [ObjectId]
}

3. Queues Collection

The queues collection stores information about processing queues.

Document Structure:

{
  _id: String,
  queue: [ObjectId]
}

Interaction Patterns

SceneManager

The SceneManager is responsible for interacting with the scenes collection.

Key Methods:

  • SetTrainingConfig(ctx, id, config)
  • SetScene(ctx, id, scene)
  • SetVideo(ctx, id, vid)
  • SetSfm(ctx, id, sfm)
  • SetNerf(ctx, id, nerf)
  • SetSceneName(ctx, id, name)
  • GetSceneName(ctx, id)
  • GetTrainingConfig(ctx, id)
  • GetScene(ctx, id)
  • GetVideo(ctx, id)
  • GetSfm(ctx, id)
  • GetNerf(ctx, id)
  • DeleteScene(ctx, id)

UserManager

The UserManager is responsible for interacting with the users collection.

Key Methods:

  • SetUser(ctx, user)
  • UpdateUser(ctx, user)
  • GenerateUser(ctx, username, password)
  • GetUserByID(ctx, userID)
  • GetUserByUsername(ctx, username)
  • UserHasJobAccess(ctx, userID, jobID)
  • UpdatePassword(ctx, userID, oldPassword, newPassword)
  • UpdateUsername(ctx, userID, userPassword, newUsername)

QueueListManager

The QueueListManager is responsible for interacting with the queues collection.

Key Methods:

  • AddNewQueue(ctx, queueID)
  • GetQueuePosition(ctx, queueID, itemID)
  • GetQueueSize(ctx, queueID)
  • AppendToQueue(ctx, queueID, itemID)
  • DeleteFromQueue(ctx, queueID, itemID)

Error Handling

Custom errors are defined for various scenarios:

  • ErrSceneNotFound
  • ErrVideoNotFound
  • ErrSfmNotFound
  • ErrNerfNotFound
  • ErrTrainingConfigNotFound
  • ErrUserNotFound
  • ErrUsernameTaken
  • ErrUserNoAccess
  • ErrInvalidQueueID
  • ErrQueueAlreadyExists
  • ErrIDAlreadyInQueue
  • ErrIDNotFoundInQueue
  • ErrMultipleIDsInQueue
  • ErrInvalidOpOnEmptyQueue

These errors should be handled appropriately in the application logic.

Security Considerations

  • Ensure that all database credentials are securely stored and not exposed in the codebase.
  • Use environment variables or secure secret management systems for storing sensitive information.
  • Implement proper access controls and authentication mechanisms for database access.