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

Measures/Dimensions/system of measurements + table/row/col/cell #4144

Open
12 tasks
minotogna opened this issue Nov 26, 2024 · 0 comments
Open
12 tasks

Measures/Dimensions/system of measurements + table/row/col/cell #4144

minotogna opened this issue Nov 26, 2024 · 0 comments
Labels
enhancement New feature or request refactor Code quality improvement
Milestone

Comments

@minotogna
Copy link
Member

minotogna commented Nov 26, 2024

TODO

  • Meta + DB Definition
  • FRA Migration
  • PanEuropean Migration
  • BE: Metadata cache generation
  • BE: Fetch assessments/metadata
  • UI: Render DataTable (without ODP) refactor
  • UI: Render DataTable with ODP
  • BE: Update nodes (w/o dependencies job)
  • BE: Update nodes dependencies job
  • UI: Update nodes
  • UI: Estimates nodes
  • UI: Data export

Code

introduce common type UUID ?

export type UUID = string

( @sorja comments: it's good idea to probably have the type of uuid in the uuid included, eg subtype uuidv4 = string uuid = uuidv4? (for discussion))

Schema: public

SystemOfMeasurement / Unit

export type SystemOfMeasurement = {
  baseUnitUUID: UUID // db
  name: string
  rules: {
    conversionFactor: Record<UUID, number> // conversion factor of each unit in relation to base unit
  }
  uuid: UUID
}

export type Unit = {
  name: string
  systemOfMeasurementUUIDs: Array<UUID> // a unit can belong to several system of units of measurement
  uuid: UUID
}
/**
 * DB TABLES
 * ==== system_of_measurement
 * id,uuid,base_unit_uuid,name (unique),
 *
 * * ==== system_of_measurement_conversion_factor
 * id,system_of_measurement_uuid,unit_uuid
 *
 * ==== unit
 * id,uuid,name(unique)
 *
 * ==== unit_system_of_measurement
 * id,system_of_measurement_uuid,unit_uuid
 *
 */
// ==== sample
export const area: SystemOfMeasurement = {
  baseUnitUUID: '',
  name: 'area',
  rules: { conversionFactor: {} },
  uuid: UUIDs.v4(),
}

export const haThousand: Unit = { name: 'haThousand', systemOfMeasurementUUIDs: [area.uuid], uuid: UUIDs.v4() }
export const ha: Unit = { name: 'ha', systemOfMeasurementUUIDs: [area.uuid], uuid: UUIDs.v4() }
export const kmSq: Unit = { name: 'kmSq', systemOfMeasurementUUIDs: [area.uuid], uuid: UUIDs.v4() }
export const mileSq: Unit = { name: 'mileSq', systemOfMeasurementUUIDs: [area.uuid], uuid: UUIDs.v4() }
export const acre1000: Unit = { name: 'acre1000', systemOfMeasurementUUIDs: [area.uuid], uuid: UUIDs.v4() }
export const acre: Unit = { name: 'acre', systemOfMeasurementUUIDs: [area.uuid], uuid: UUIDs.v4() }
export const haMillion: Unit = { name: 'haMillion', systemOfMeasurementUUIDs: [area.uuid], uuid: UUIDs.v4() }

area.baseUnitUUID = haThousand.uuid
area.rules.conversionFactor = {
  [area.baseUnitUUID]: 1,
  [ha.uuid]: 1000,
  [kmSq.uuid]: 10,
  [mileSq.uuid]: 3.86102,
  [acre1000.uuid]: 2.47105,
  [acre.uuid]: 2471.05,
  [haMillion.uuid]: 0.001,
}
// ==== end sample

Category / Dimension / Measure

export type Category = {
  dimensions?: Array<Dimension> // not db column - lazy loaded
  name: string
  uuid: UUID
}
// TODO: Should Dimension have a value? (e.g. value for numerical columns like 1990 - name='1990',value=1990) useful?
export type Dimension = {
  categoryUUIDs: Array<UUID>
  name: string
  uuid: UUID
}
/**
 * DB TABLES
 * ==== category
 * id,uuid,name (unique),
 *
 * * ==== dimension
 * id,uuid,name (unique),
 *
 * ==== category_dimension
 * id,category_uuid,dimension_uuid
 *
 */
export enum MeasureType {
  // TODO: Question (decimal and integer)
  decimal = 'decimal',
  integer = 'integer',
  // TODO: OR only number - and handle input mode decimal/integer)
  number = 'number',

  // AND text
  text = 'text',
}

export type Measure = {
  name: string
  type: MeasureType
  unitUUID: UUID
  uuid: UUID
}

Schema: assessment_cycle

Observation

export type Observation = {
  countryIso: CountryIso
  dimensionUUID: UUID
  measureUUID: UUID
  unitUUID: UUID
  uuid: UUID
  value: NodeValue
}

AxisItem = Col | Row / Cell

// AxisItem = Col | Row
type AxisItem = {
  props: {
    dimensionUUID?: UUID // can be used in design mode to link a dimension to a specific (col or row)
    index: number
    measureUUID?: UUID // can be used in design mode to link a measure to a specific (col or row)
  }
  tableUUID: UUID
  uuid: UUID
}

export type Col = AxisItem

export type Row = AxisItem & {
  cells: Array<Cell> // added in repository getters
}
//= ==== (ex Col)
export type Cell = {
  rowUUID: UUID
  uuid: UUID
  props: {
    // colName?: removed
    // colType: removed

    // ==== COMMON props
    classNames?: Record<CycleUuid, Array<string>> // TODO: Check what and where it's used
    index: number // migrate from number|string(header)
    style?: Record<CycleUuid, ColStyle> // TODO: Check what it's used (colSpan,rowSpan and ?)
    type: 'text|label' | 'observation' // TODO: Check where colType placeholder is used

    // ====  EITHER labels
    labels?: Record<CycleUuid, Label>

    // ==== OR
    calculateFn?: Record<CycleUuid, string>
    dimensionUUID?: UUID // new
    inputPlaceholder?: string
    linkedNodes?: Record<CycleUuid, ColLinkedNode> // TODO: Check - can we use calculateFn instead?
    measureUUID?: UUID // new
    multiline?: boolean // new: ex colType textarea
    readonly?: boolean
    select?: Record<CycleUuid, ColSelectProps> // ex colType select
    validateFns?: Record<CycleUuid, Array<string>>
    variableNo?: Record<CycleUuid, string> // TODO: Check where it's used
  }
}
@minotogna minotogna added this to the 4.0.0 milestone Nov 26, 2024
@minotogna minotogna added enhancement New feature or request refactor Code quality improvement labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor Code quality improvement
Projects
None yet
Development

No branches or pull requests

1 participant