I am working on a web application that store a lot of measurement data.
These measures have different types like temperature, flow, weight, concentration…
I am currently trying to implement a measurement units manager to let the users of the application choose which unit they want for each measure.
The data is in multiple tables :
Table1 : weightMeasure1 lengthMeasure1 TemperatureMeasure1
Table2 : weightMeasure2 lengthMeasure2 FlowMeasure2
Table3 : flowMeasure3
The users will be able to choose the unit that they want for each measure independently. So it will not be a metric/imperial choice.
All the data will be saved in there SI or SI derived unit in the Database. Because I am using PHP for my application I decided to use Zend_Measure to handle the conversion (after asking this question).
How to define the unit of each measures in my database?
How to manage the user unit preferences?
This is the best solution that I have so far :
I will create a property table :
property : property_id name column unit
- property_id is a unique incremented number (PK)
- name is a human readable name (optional)
- column is a concatenation of the table name and the column name (Unique constraint). For example :
table2_lengthMeasure2 - unit is the Zend constant string defining the unit of the property in the database. For example :
SQUARE_METER,KILOGRAM_PER_HOUR, … more details available in the Zend Framework API.
I will create a user_property_unit table to manage the user preferences :
user_property_unit : user_id property_id unit
- unit is the Zend constant string defining the unit of the property when it will be display in the UI for the user. For example it can be
SQUARE_METERin the unit column of thepropertytable andSQUARE_FOOTin the unit column of theuser_property_unit
The problems that I see with this solution are:
- Using the concat of
table name + column nameseems not right to me… - If I change the name of one of my columns it will not be reflected in the
propertytable.
Thanks for your Help!!
UPDATE
Is there any one why can help me even with some tips?
You want to have a separate table for PROPERTIES and a separate linking table TABLECOLUMNPROPERTY that makes a specific property the attribute of the column.