removed old database dumps

added description howto create database schema
reorganized channel models
This commit is contained in:
Steffen Vogel 2010-07-19 18:55:18 +02:00
parent 5923ae8940
commit 4a5f8476eb
12 changed files with 92 additions and 6918 deletions

View file

@ -24,22 +24,40 @@ namespace Volkszaehler\Controller;
use \Volkszaehler\Model;
class Channel extends Controller {
// TODO authentification/indentification
public function get() {
// TODO filter by uuid, type etc...
$channels = $this->em->getRepository('Volkszaehler\Model\Channel\Channel')->findAll();
$dql = 'SELECT c FROM Volkszaehler\Model\Channel\Channel c JOIN WHERE';
$conditions = array();
if ($this->view->request->getParameter('uuid')) {
$conditions['uuid'] = $this->view->request->getParameter('uuid');
}
if ($this->view->request->getParameter('ugid')) {
}
if ($this->view->request->getParameter('indicator')) {
}
$q = $this->em->createQuery($dql);
$channels = $q->getResult();
foreach ($channels as $channel) {
$this->view->add($channel);
}
}
// TODO validate input and throw exceptions
public function add() {
// TODO validate input
$channel = new Model\Channel\Meter('power');
$channel = new Model\Channel\Meter($this->view->request->getParameter('indicator'));
$channel->setName($this->view->request->getParameter('name'));
$channel->setResolution($this->view->request->getParameter('resolution'));
$channel->setDescription($this->view->request->getParameter('description'));
$channel->setResolution($this->view->request->getParameter('resolution'));
$channel->setCost($this->view->request->getParameter('cost'));
$this->em->persist($channel);
@ -48,7 +66,7 @@ class Channel extends Controller {
$this->view->add($channel);
}
// TODO check for valid user identity
// TODO authentification/indentification
public function delete() {
$ucid = $this->view->request->getParameter('ucid');
$channel = $this->em->getRepository('Volkszaehler\Model\Channel\Channel')->findOneBy(array('uuid' => $ucid));
@ -57,8 +75,10 @@ class Channel extends Controller {
$this->em->flush();
}
// TODO implement ChannelController::edit();
// TODO authentification/indentification
public function edit() {
// TODO implement ChannelController::edit();
}
}

View file

@ -32,15 +32,6 @@ class Data extends Controller {
$from = ($this->view->request->getParameter('from')) ? (int) $this->view->request->getParameter('from') : NULL;
$to = ($this->view->request->getParameter('to')) ? (int) $this->view->request->getParameter('to') : NULL;
$groupBy = ($this->view->request->getParameter('groupBy')) ? $this->view->request->getParameter('groupBy') : NULL; // get all readings by default
switch ($this->view->request->getParameter('type')) {
case 'power':
case 'consumption':
case 'stats':
}
foreach ($channels as $channel) {
$interpreter = $channel->getInterpreter($this->em);

View file

@ -70,8 +70,11 @@ abstract class Interpreter implements InterpreterInterface {
default:
if (is_numeric($groupBy)) { // lets agrregate it with php
$groupBy = (int) $groupBy;
$sqlGroupBy = false;
}
else {
throw new \InvalidArgumentException('\'' . $groupBy . '\' is not an unknown grouping mode');
}
$sqlGroupBy = false;
}
$sql = 'SELECT';

View file

@ -19,7 +19,7 @@
* http://www.gnu.org/copyleft/gpl.html
*/
namespace Volkszaehler\Model\Channel;
namespace Volkszaehler\Model;
use Doctrine\Common\Collections\ArrayCollection;
@ -28,14 +28,8 @@ use Doctrine\Common\Collections\ArrayCollection;
*
* @Entity
* @Table(name="channels")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="type", type="string")
* @DiscriminatorMap({
* "meter" = "Meter",
* "sensor" = "Sensor"
* })
*/
abstract class Channel extends \Volkszaehler\Model\Entity {
abstract class Channel extends Entity {
/** @Column(type="string") */
protected $name;
@ -46,32 +40,45 @@ abstract class Channel extends \Volkszaehler\Model\Entity {
protected $indicator;
/**
* @OneToMany(targetEntity="Volkszaehler\Model\Data", mappedBy="channel"), cascade={"remove"}
* @OneToMany(targetEntity="Data", mappedBy="channel"), cascade={"remove"}
*/
private $data = NULL;
/** @Column(type="integer") */
private $resolution;
/** @Column(type="decimal") */
private $cost;
/*
* indicator => interpreter, unit mapping
*/
protected static $indicators = array(
'power' => array('meter', 'kW/h'),
'gas' => array('meter', 'qm/h'),
'water' => array('meter', 'qm/h'),
'temperature' => array('sensor', '° C'),
'pressure' => array('sensor', 'hPa'),
'humidity' => array('sensor', '%')
);
/*
* constructor
*/
public function __construct($indicator) {
parent::__construct();
if (!in_array($indicator, self::$indicators)) {
throw new \InvalidArgumentException($indicator . ' is no known indicator');
}
$this->indicator = $indicator;
$this->data = new ArrayCollection();
}
/*
* getter & setter
*/
public function getName() { return $this->name; }
public function setName($name) { $this->name = $name; }
public function getDescription() { return $this->description; }
public function setDescription($description) { $this->description = $description; }
public function getUnit() { return static::$indicators[$this->indicator]; }
public function getIndicator() { return $this->indicator; }
/*
* add a new data to the database
* @todo move to logger?
*/
public function addData(\Volkszaehler\Model\Data $data) {
$this->data->add($data);
@ -81,10 +88,24 @@ abstract class Channel extends \Volkszaehler\Model\Entity {
* obtain channels data interpreter to calculate statistical information
*/
public function getInterpreter(\Doctrine\ORM\EntityManager $em) {
$interpreterClassName = 'Volkszaehler\Interpreter\\' . substr(strrchr(get_class($this), '\\'), 1);
$interpreterClassName = 'Volkszaehler\Interpreter\\' . ucfirst(self::$indicators[$this->indicator][0]);
if (!(\Volkszaehler\Util\ClassLoader::classExists($interpreterClassName)) || !is_subclass_of($interpreterClassName, '\Volkszaehler\Interpreter\Interpreter')) {
throw new \InvalidArgumentException('\'' . $interpreterClassName . '\' is not a valid Interpreter');
}
return new $interpreterClassName($this, $em);
}
/*
* getter & setter
*/
public function getName() { return $this->name; }
public function setName($name) { $this->name = $name; }
public function getDescription() { return $this->description; }
public function setDescription($description) { $this->description = $description; }
public function getUnit() { return self::$indicators[$this->indicator][1]; }
public function getIndicator() { return $this->indicator; }
public function getResolution() { return $this->resolution; }
public function setResolution($resolution) { $this->resolution = $resolution; }
public function getCost() { return $this->cost; }
public function setCost($cost) { $this->cost = $cost; }
}

View file

@ -1,49 +0,0 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
namespace Volkszaehler\Model\Channel;
/**
* Meter class
*
* @Entity
*/
class Meter extends Channel {
/** @Column(type="integer") */
private $resolution;
/** @Column(type="decimal") */
private $cost;
/*
* indicator => unit mapping
*/
protected static $indicators = array(
'power' => 'kW/h',
'gas' => 'qm/h',
'water' => 'qm/h'
);
public function getResolution() { return $this->resolution; }
public function setResolution($resolution) { $this->resolution = $resolution; }
public function getCost() { return $this->cost; }
public function setCost($cost) { $this->cost = $cost; }
}

View file

@ -1,39 +0,0 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
namespace Volkszaehler\Model\Channel;
/**
* Channel class
*
* @Entity
*/
class Sensor extends Channel {
/*
* indicator => unit mapping
*/
protected static $indicators = array(
'temperature' => '° C',
'pressure' => 'hPa',
'humidity' => '%'
);
}

View file

@ -44,7 +44,7 @@ class Data {
/**
* @Id
* @ManyToOne(targetEntity="Volkszaehler\Model\Channel\Channel", inversedBy="data")
* @ManyToOne(targetEntity="Channel", inversedBy="data")
* @JoinColumn(name="channel_id", referencedColumnName="id")
*/
private $channel;

View file

@ -37,7 +37,7 @@ class Group extends Entity {
private $description;
/**
* @ManyToMany(targetEntity="Volkszaehler\Model\Channel\Channel")
* @ManyToMany(targetEntity="Channel")
* @JoinTable(name="groups_channel",
* joinColumns={@JoinColumn(name="group_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="channel_id", referencedColumnName="id")}

18
share/sql/README Normal file
View file

@ -0,0 +1,18 @@
volkzaehler.org uses doctrine [1] as database abstraction and object relation model.
To setup your database follow these steps:
1. Make sure you have a proper configuration file (backend/volkszaehler.conf.php)
2. Adjust the configuration to your database setup
3. Call backend/bin/doctrine orm:schema-tool:create
Alternative way:
This folder contains some SQL dumps which can be imported in your database.
Be aware that these dumps can be outdated!
These dumps are generated with doctrine schema-tool:
backend/bin/doctrine orm:schema-tool:create --dump-sql > share/sql/mysql.sql
[1] http://www.doctrine-project.org

File diff suppressed because it is too large Load diff

View file

@ -1,142 +0,0 @@
-- phpMyAdmin SQL Dump
-- version 3.3.2deb1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Erstellungszeit: 14. Juni 2010 um 00:36
-- Server Version: 5.1.41
-- PHP-Version: 5.3.2-1ubuntu4.2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Datenbank: `volkszaehler_nested`
--
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `channels`
--
DROP TABLE IF EXISTS `channels`;
CREATE TABLE `channels` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uuid` varchar(36) CHARACTER SET latin1 NOT NULL COMMENT 'Universally Unique Identifier',
`type` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'Channel' COMMENT 'maps meter to classname (caseinsensitive)',
`resolution` int(11) DEFAULT NULL,
`cost` int(11) DEFAULT '0',
`description` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='channels with detailed data';
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `channels_in_groups`
--
DROP TABLE IF EXISTS `channels_in_groups`;
CREATE TABLE `channels_in_groups` (
`channel_id` int(11) NOT NULL,
`group_id` int(11) NOT NULL,
KEY `channel_id` (`channel_id`),
KEY `group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `data`
--
DROP TABLE IF EXISTS `data`;
CREATE TABLE `data` (
`channel_id` int(11) NOT NULL,
`timestamp` bigint(20) NOT NULL COMMENT 'in seconds since 1970',
`value` float NOT NULL COMMENT 'absolute sensor value or pulse since last timestamp (dependening on "meters.type")',
KEY `channel_id` (`channel_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='data for all meters, regardless of which type they are';
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `groups`
--
DROP TABLE IF EXISTS `groups`;
CREATE TABLE `groups` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`left` int(11) NOT NULL,
`right` int(11) NOT NULL,
`uuid` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Universally Unique Identifier',
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`description` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`),
KEY `right` (`right`),
KEY `left` (`left`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `users`
--
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uuid` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Universally Unique Identifier',
`email` varchar(255) CHARACTER SET latin1 NOT NULL COMMENT 'also used for login',
`password` varchar(40) CHARACTER SET latin1 NOT NULL COMMENT 'SHA1() hashed',
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `uuid` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='users with detailed data';
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `users_in_groups`
--
DROP TABLE IF EXISTS `users_in_groups`;
CREATE TABLE `users_in_groups` (
`group_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`role` enum('member','owner') NOT NULL,
KEY `user_id` (`user_id`),
KEY `group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Constraints der exportierten Tabellen
--
--
-- Constraints der Tabelle `channels_in_groups`
--
ALTER TABLE `channels_in_groups`
ADD CONSTRAINT `channels_in_groups_ibfk_3` FOREIGN KEY (`channel_id`) REFERENCES `channels` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `channels_in_groups_ibfk_4` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE;
--
-- Constraints der Tabelle `data`
--
ALTER TABLE `data`
ADD CONSTRAINT `data_ibfk_1` FOREIGN KEY (`channel_id`) REFERENCES `channels` (`id`) ON DELETE CASCADE;
--
-- Constraints der Tabelle `users_in_groups`
--
ALTER TABLE `users_in_groups`
ADD CONSTRAINT `users_in_groups_ibfk_3` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `users_in_groups_ibfk_4` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

View file

@ -1,84 +0,0 @@
--
-- PostgreSQL database dump
--
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: channels; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
--
CREATE TABLE channels (
function character(100),
resolution INTEGER NOT NULL DEFAULT 1000,
id integer NOT NULL,
uuid uuid NOT NULL,
CONSTRAINT channels_id PRIMARY KEY (id)
);
CREATE UNIQUE INDEX channels_uuid ON channels (uuid);
COMMENT ON COLUMN channels.function IS 'description of what this meter is used for';
COMMENT ON COLUMN channels.resolution IS 'resolution of power meter [pulses/kWh]';
--
-- Name: pulses; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
--
CREATE TABLE pulses (
servertime timestamp without time zone NOT NULL,
controllertime timestamp without time zone NOT NULL,
channel_id integer NOT NULL REFERENCES channels(id) ON DELETE CASCADE,
time_delta real
);
-- solange nach servertime gesucht wird
CREATE INDEX pulses_servertime ON pulses (servertime);
COMMENT ON COLUMN pulses.time_delta IS 'difference between controllertime and servertime';
REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT USAGE ON SCHEMA public TO smreader;
GRANT USAGE ON SCHEMA public TO smlogger;
--
-- Name: channels; Type: ACL; Schema: public; Owner: postgres
--
REVOKE ALL ON TABLE channels FROM PUBLIC;
REVOKE ALL ON TABLE channels FROM postgres;
GRANT ALL ON TABLE channels TO postgres;
GRANT SELECT ON TABLE channels TO smlogger;
GRANT SELECT ON TABLE channels TO smreader;
--
-- Name: pulses; Type: ACL; Schema: public; Owner: postgres
--
REVOKE ALL ON TABLE pulses FROM PUBLIC;
REVOKE ALL ON TABLE pulses FROM postgres;
GRANT ALL ON TABLE pulses TO postgres;
GRANT INSERT ON TABLE pulses TO smlogger;
GRANT SELECT ON TABLE pulses TO smreader;
--
-- PostgreSQL database dump complete
--