moved definition files

This commit is contained in:
Steffen Vogel 2010-09-19 20:40:37 +02:00
parent 48275a1bf5
commit 87b028849b
4 changed files with 468 additions and 22 deletions

View file

@ -23,39 +23,63 @@
namespace Volkszaehler\Model;
use Volkszaehler\Util;
/**
* @author Steffen Vogel <info@steffenvogel.de>
* @package default
*/
class EntityDefinition extends Definition {
/** @var string File containing the JSON definitons */
const FILE = '/share/entities.json';
/**
* File containing the JSON definitons
*
* @var string
*/
const FILE = '/share/definitions/entities.json';
/** @var array list of required properties */
/**
* List of required properties
*
* @var array
*/
protected $required = array();
/** @var array list of optional properties */
/**
* List of optional properties
*
* @var array
*/
protected $optional = array();
/** @var string classname of intepreter (see backend/lib/Interpreter/) */
/**
* Classname of intepreter (see backend/lib/Interpreter/)
*
* @var string
*/
protected $interpreter;
/** @var string optional for Aggregator class entities */
/**
* Optional for Aggregator class entities
*
* @var string
*/
protected $unit;
static protected $definitions = NULL;
/**
* @todo url relative or absolute?
* @var string
*/
protected $icon;
static protected $definitions = NULL;
/*
* Setter & Getter
*/
public function getInterpreter() { return $this->interpreter; }
public function getUnit() { return $this->unit; }
public function getRequiredProperties() { return $this->required; }
public function getValidProperties() { return array_merge($this->required, $this->optional); }
}
?>

View file

@ -28,10 +28,25 @@ namespace Volkszaehler\Model;
* @package default
*/
class PropertyDefinition extends Definition {
/** One of: string, integer, float, boolean, multiple */
/**
* File containing the JSON definitons
*
* @var string
*/
const FILE = '/share/definitions/properties.json';
/**
* One of: string, integer, float, boolean, multiple
*
* @var string
*/
protected $type;
/** @var string regex pattern to match if type == string */
/**
* Regex pattern to match if type == string
*
* @var string
*/
protected $pattern;
/**
@ -60,14 +75,6 @@ class PropertyDefinition extends Definition {
protected static $definitions = NULL;
/**
* File containing the JSON definitons
*
* @var string
*/
const FILE = '/share/properties.json';
/**
* Validate value according to $this->type
*
@ -84,15 +91,15 @@ class PropertyDefinition extends Definition {
break;
case 'integer':
$invalid = !is_int($value); // TODO check for numeric string
$invalid = !is_int($value);
break;
case 'float':
$invalid = !is_float($value); // TODO check for numeric string
$invalid = !is_float($value);
break;
case 'boolean':
$invalid = !is_bool($value); // TODO check for numeric string
$invalid = !is_bool($value);
break;
case 'multiple':
@ -100,7 +107,7 @@ class PropertyDefinition extends Definition {
break;
default:
throw new \Exception('unknown property type');
throw new \Exception('Unknown property type: ' . $type);
}
if ($this->type == 'integer' || $this->type == 'float') {

View file

@ -0,0 +1,113 @@
/**
* Definition of entities
* Format is specified in EntityDefinition class
*
* @author Steffen Vogel <info@steffenvogel.de>
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package default
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
[
{
"name" : "group",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "tolerance"],
"interpreter" : "AggregatorInterpreter",
"icon" : "" // TODO look for an icon
},
{
"name" : "user",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "tolerance"],
"interpreter" : "AggregatorInterpreter",
"icon" : "" // TODO look for an icon
},
{
"name" : "power",
"required" : ["title", "resolution"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "MeterInterpreter",
"unit" : "kW/h",
"icon" : "" // TODO look for an icon
},
{
"name" : "gas",
"required" : ["title", "resolution"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "MeterInterpreter",
"unit" : "m³/h",
"icon" : "" // TODO look for an icon
},
{
"name" : "water",
"required" : ["title", "resolution"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "MeterInterpreter",
"unit" : "m³/h",
"icon" : "" // TODO look for an icon
},
{
"name" : "temperature",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"unit" : "°C",
"icon" : "" // TODO look for an icon
},
{
"name" : "pressure",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"unit" : "hPa",
"icon" : "" // TODO look for an icon
},
{
"name" : "humidity",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"unit" : "%",
"icon" : "" // TODO look for an icon
},
{
"name" : "windspeed",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"unit" : "km/h",
"icon" : "" // TODO look for an icon
},
{
"name" : "radition",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"icon" : "" // TODO look for an icon
},
{
"name" : "luminosity",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"icon" : "" // TODO look for an icon
}
]

View file

@ -0,0 +1,302 @@
/**
* Definition of properties for entities
*
* Format is specified in PropertyDefinition class
*
* @author Steffen Vogel <info@steffenvogel.de>
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package default
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
[
{
"name" : "title",
"type" : "string",
"pattern" : "/[a-z0-9 ]/",
"min": 3,
"max" : 255
},
{
"name" : "description",
"type" : "string",
"pattern" : "/[a-z0-9 ]/", // TODO add whitespaces as \t \n \r
"max" : 255, // TODO allowed column size in database?
"min" : 5
},
{
"name" : "cost",
"type" : "float",
"min" : 0
},
{
"name" : "resolution",
"type" : "integer",
"min" : 1
},
{
"name" : "tolerance",
"type" : "float",
"min" : 0,
"max" : 1
},
{
"name" : "address:lat",
"type" : "float",
"min" : -90,
"max" : 90
},
{
"name" : "address:lon",
"type" : "float",
"min" : -90,
"max" : 90
},
{
"name" : "address:city",
"type" : "string",
"pattern" : "" // TODO add pattern
},
{
"name" : "address:houseno",
"type" : "string"
},
{
"name" : "address:postal",
"type" : "string"
},
{
"name" : "address:state",
"type" : "multiple",
"choices" : [
"Albania",
"Algeria",
"Andorra",
"Angola",
"Anguilla",
"Antigua and Barbuda",
"Argentina",
"Armenia",
"Aruba",
"Australia",
"Austria",
"Azerbaijan Republic",
"Bahamas",
"Bahrain",
"Barbados",
"Belgium",
"Belize",
"Benin",
"Bermuda",
"Bhutan",
"Bolivia",
"Bosnia and Herzegovina",
"Botswana",
"Brazil",
"British Virgin Islands",
"Brunei",
"Bulgaria",
"Burkina Faso",
"Burundi",
"Cambodia",
"Canada",
"Cape Verde",
"Cayman Islands",
"Chad",
"Chile",
"China Worldwide",
"Colombia",
"Comoros",
"Cook Islands",
"Costa Rica",
"Croatia",
"Cyprus",
"Czech Republic",
"Democratic Republic of the Congo",
"Denmark",
"Djibouti",
"Dominica",
"Dominican Republic",
"Ecuador",
"El Salvador",
"Eritrea",
"Estonia",
"Ethiopia",
"Falkland Islands",
"Faroe Islands",
"Federated States of Micronesia",
"Fiji",
"Finland",
"France",
"French Guiana",
"French Polynesia",
"Gabon Republic",
"Gambia",
"Germany",
"Gibraltar",
"Greece",
"Greenland",
"Grenada",
"Guadeloupe",
"Guatemala",
"Guinea",
"Guinea Bissau",
"Guyana",
"Honduras",
"Hong Kong",
"Hungary",
"Iceland",
"India",
"Indonesia",
"Ireland",
"Israel",
"Italy",
"Jamaica",
"Japan",
"Jordan",
"Kazakhstan",
"Kenya",
"Kiribati",
"Kuwait",
"Kyrgyzstan",
"Laos",
"Latvia",
"Lesotho",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Martinique",
"Mauritania",
"Mauritius",
"Mayotte",
"Mexico",
"Mongolia",
"Montserrat",
"Morocco",
"Mozambique",
"Namibia",
"Nauru",
"Nepal",
"Netherlands",
"Netherlands Antilles",
"New Caledonia",
"New Zealand",
"Nicaragua",
"Niger",
"Niue",
"Norfolk Island",
"Norway",
"Oman",
"Palau",
"Panama",
"Papua New Guinea",
"Peru",
"Philippines",
"Pitcairn Islands",
"Poland",
"Portugal",
"Qatar",
"Republic of the Congo",
"Reunion",
"Romania",
"Russia",
"Rwanda",
"Saint Vincent and the Grenadines",
"Samoa",
"San Marino",
"São Tomé and Príncipe",
"Saudi Arabia",
"Senegal",
"Seychelles",
"Sierra Leone",
"Singapore",
"Slovakia",
"Slovenia",
"Solomon Islands",
"Somalia",
"South Africa",
"South Korea",
"Spain",
"Sri Lanka",
"St. Helena",
"St. Kitts and Nevis",
"St. Lucia",
"St. Pierre and Miquelon",
"Suriname",
"Svalbard and Jan Mayen Islands",
"Swaziland",
"Sweden",
"Switzerland",
"Taiwan",
"Tajikistan",
"Tanzania",
"Thailand",
"Togo",
"Tonga",
"Trinidad and Tobago",
"Tunisia",
"Turkey",
"Turkmenistan",
"Turks and Caicos Islands",
"Tuvalu",
"Uganda",
"Ukraine",
"United Arab Emirates",
"United Kingdom",
"Uruguay",
"Vanuatu",
"Vatican City State",
"Venezuela",
"Vietnam",
"Wallis and Futuna Islands",
"Yemen",
"Zambia"
]
},
{
"name" : "address:country",
"type" : "string"
},
{
"name" : "photo:url",
"type" : "string",
"pattern" : "" // TODO add pattern
},
{
"name" : "cuuid",
"type" : "string",
"max" : 37
},
{
"name" : "port",
"type" : "string",
"max" : 6
},
{
"name" : "active",
"type" : "boolean"
}
]