What this system is, is a home automation system. The system consists of 
many IO devices that are managed by central base unit in the house. Examples 
of these devices are:

A media player
A water tank float level
A thermometer
A heater

The part I am working on is an external remote sub-system that allows home 
owners to configure and monitor these devices and their entire house from a 
web frontend. The table in question resides within this system.

By far an large, the format of these values is for human readable display 
purposes in this sub-system only. The actual hardware in the house only 
cares about the value itself.

I.E.

1. Displaying the default volume of a media player (when someone turns it 
on) should be displayed as an integer on the frontend (despite the value in 
the db being stored with 6 decimal accuracy)
2. Displaying the water tank level might be displayed with 2 decimal 
accuracy
3. Displaying a thermometer might have 1 decimal accuracy.

The core of my question is what would be the best way for managing the 
formatting itself.

As far as PHP code goes, the idea is to obtain a display format based on the 
device the user is viewing on the page, and then using this format (whatever 
it may be) to display the value correctly to the user.

Example. The thermometer max temperature might be 49.999999 dB in the 
database (decimal datatype). On screen however, we might want to display 
this to the user as "49.9°C (Degrees Celcius)". The level of accuracy in the 
Database is as such to future proof the system for devices that are being 
actively researched.

The main question for me is how I store this format, and how I implement 
that in code. E.G. A string holding a number_format argument set? A custom 
masking system using str_replace in the code.

After thinking through this myself, separate fields holding decimal length, 
unit name ("Degrees"/"DB","Litres") and unit symbol might be the way to go. 
Concatinating all these values in the code in a number_format/printf 
function.

Basically I'm asking if anyone has ever designed a similar masking system 
and if there is any best practises for this.

Aaron


----- Original Message ----- 
From: "Jared Armstrong" <[EMAIL PROTECTED]>
To: "NZ PHP Users Group" <[email protected]>
Sent: Saturday, November 15, 2008 2:37 PM
Subject: [phpug] Re: Storing printf format statments in Database?



I think using a View for this is overkill, unless the data was
accessed through means other than the page/program that is displaying
this formatting (ie. there are multiple applications accessing the
database).

Depending on how complicated you want your formatting, why not store
each formatting data as a "template" in a table somewhere.

Can use Dwoo (http://www.dwoo.org), and in PHP parse the string as
DwooTemplate string. Obviously, you can use any template engine - Dwoo
was just an example.

Alternatively, can just store it as PHP code and eval().

Or for simple formatting, just store it as a sprintf() formatting
string, and pass the arguments in a set order (you can use argument
swapping if the display you want has them in a different order).




On Nov 14, 11:56 am, "Aaron Cooper" <[EMAIL PROTECTED]> wrote:
> Howdy folks,
>
> I have a bit of a weird one, and it's more to do with design than coding 
> of any sort.
>
> To keep things simple:
>
> We have a MySQL table called display_type. This table is used to store 
> config data for a range of physical devices that do certain jobs. This 
> table holds Min Value, Max Value, Default Value, Unit.
>
> The data stored in this table can pertain to many devices that work with 
> different sets of variables. E.G. It could be a media player, where Min, 
> Max and Default Vals are volume settings. It could be a thermometer where 
> Min, Max and Default are temperature ranges for display purposes only.
>
> Because there is such a wide range of formats for this table, each with a 
> different way of displaying these values to the user, we also want to 
> store a display format for each record to use in printf or number_format 
> functions in the code. Not too different to how you format numbers in 
> Excel.
>
> The table in question is more of a lookup table with a finite data 
> collection, although it will be added to as time goes by. It is maintained 
> by us, and us alone (no user input will reach it)
>
> All the values (Min, Max, Default and Current) are stored MySQL's decimal 
> format with 6 decimal places.
>
> Any ideas on the best way of storing formatting (and later using in PHP) 
> masks like this?
>
> Oh, and and by the way, the backend is being built on the Zend Framework 
> if anyone is aware of a nifty way one of those libraries can aid in this.
>
> Cheers
> Aaron



--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to