Effektstatistik

query('select * from `wind_data` order by `date_and_time` desc limit 1')->fetch();

$current_effect = $measurement['effect'];
$current_speed = $measurement['speed'];
$current_degrees = $measurement['degrees'];

$monthNames = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec');

// Alla år och månader
$months = $pdh->query("
select
date_format(`date_and_time`, '%Y') as year,
date_format(`date_and_time`, '%m') as month
from
`wind_data`
group by
date_format(`date_and_time`, '%Y-%m')
order by
year desc, month desc
")->fetchAll(PDO::FETCH_ASSOC);

// Alla år
$years = $pdh->query("
select
date_format(`date_and_time`, '%Y') as year
from
`wind_data`
group by
date_format(`date_and_time`, '%Y')
order by
year desc
")->fetchAll(PDO::FETCH_ASSOC);

// Effekt per dag senaste veckan, t.o.m. igår
$lastWeek = $pdh->query("
select
date_format(`date_and_time`, '%m') as month,
date_format(`date_and_time`, '%w') as weekday,
date_format(`date_and_time`, '%d') as date,
sum(effect) as dayeffect
from
`wind_data`
where
`date_and_time`>= curdate() - INTERVAL DAYOFWEEK(curdate())+4 DAY AND `date_and_time`fetchAll(PDO::FETCH_ASSOC);

//print_r($lastWeek);

// Effekt per månad för alla månader (för alla år)
$power_per_month = $pdh->query("
select
date_format(`date_and_time`, '%Y') as year,
date_format(`date_and_time`, '%m') as month,
sum(effect) as montheffect
from
`wind_data`
group by
date_format(`date_and_time`, '%Y-%m')
order by
year desc, month desc")->fetchAll(PDO::FETCH_ASSOC);
// Effekt per dag för alla dagar (för alla månader och år)
$power_per_day = $pdh->query("
select
date_format(`date_and_time`, '%Y') as year,
date_format(`date_and_time`, '%m') as month,
date_format(`date_and_time`, '%d') as day,
sum(effect) as dayeffect
from
`wind_data`
group by
date_format(`date_and_time`, '%Y-%m-%d')
order by
year desc, month desc, day desc")->fetchAll(PDO::FETCH_ASSOC);

// Effekt per år för alla år
$power_per_year = $pdh->query("
select
date_format(`date_and_time`, '%Y') as year,
sum(effect) as yeareffect
from
`wind_data`
group by
date_format(`date_and_time`, '%Y')
order by
year desc")->fetchAll(PDO::FETCH_ASSOC);

// Beräkna CO2-besparing
$effectRow = $pdh->query("
select
sum(`effect`) as totalEffect
from
`wind_data`
")->fetch(PDO::FETCH_ASSOC);

$totalEffect = ($effectRow['totalEffect'] * 434) / 1000;
$totalCO2 = ($effectRow['totalEffect'] * 434) / 1000;

wp_enqueue_script('jQ', '/javascripts/jquery-1.6.1.min.js', array(), false, true);

wp_enqueue_style('form', '/wp-content/themes/ashe-child/form.css');?>

google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {

// Create the data table.
var data_lastweek = new google.visualization.DataTable();
data.addColumn('date', 'dag');
data.addColumn('number', 'effekt');
data.addRows([<?php
for ($i=0; $i<7; $i++) {
if ($i]);

// Set chart options
var options = {'title':'Producerad effekt senaste veckan',
'width':400,
'height':300};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data_lastweek, options);
}

<!--
<div class="main-content clear-fix" data-sidebar-sticky="">
/-->

Hittills har vindkraftverket sparat ton i CO2-utsläpp.




  • Senaste veckan
  • Månad
  • Jämför månader
  • Jämför år
  • Statistik för senaste veckan (produktion i kWh)

    Statistik för en månad (produktion i kWh)

    <option data-year="" data-month="">

    Jämför månader (produktion i kWh)

    <?php
    /*
    echo("current effect ");
    echo($current_effect);
    echo("
    current speed ");
    echo($current_speed);
    echo("
    degrees ");
    echo($current_degrees);
    echo("
    month names ");
    print_r($monthNames);
    echo("
    år och månad ");
    print_r($months);
    echo("
    år ");
    print_r($years);
    echo("
    år2 ");
    print_r($years2);
    echo("
    effectrows ");
    print_r($effectRow);
    echo("
    total effekt ");
    echo($totalEffect);
    echo("
    power_per_month ");
    print_r($power_per_month);
    echo("
    power_per_day ");
    print_r($power_per_day);*/
    echo("
    lastweek ");
    /*print_r($lastWeek);
    $startdag = intval($lastWeek[0]['weekday']);
    for ($i=0; $i

    <option data-year="" data-month="">

    <option data-year="" data-month="">

    Jämför år (produktion i kWh)

    <option data-year="">

    <option data-year="">

    kg CO2 sparat under perioden

    var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'],
    weekDayNames = ['Sön', 'Mån', 'Tis', 'Ons', 'Tor', 'Fre', 'Lör'],
    chartElement = document.getElementById('chart');

    var padding = function (str) {
    return str.toString().length > 1 ? str : "0" + str;
    };

    var dateToQueryString = function (d) {
    return d.getFullYear() + "-" + padding(d.getMonth() + 1) + "-" + padding(d.getDate()) + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
    };

    window.onload = function () {

    $('#btnSelectMonth').bind('click', function (e) {
    $(chartElement).empty();
    $('.carbon-container').hide();

    var $item = $(this).closest('.inner').find('select option:selected');
    var year = $item.attr('data-year');
    var month = $item.attr('data-month');

    var to = new Date(parseInt(year), parseInt(month), 0);
    var from = new Date(parseInt(year), parseInt(month) - 1, 1);

    loadChartData(from, to, function (data) {

    var fmt = [],
    carbon = 0;
    fmt.push(['Datum', 'Produktion i kWh']);
    $.each(data, function () {
    carbon += parseInt(this.carbon);
    fmt.push([headerAsDayInMonth(this.date), parseInt(this.output)]);
    });

    drawChart(fmt, $('#month'), carbon, true);

    });
    });
    $('#btnSelectCompareMonths').bind('click', function (e) {
    $(chartElement).empty();
    $('.carbon-container').hide();

    var $fItem = $(this).closest('.inner').find('select').first().find('option:selected'),
    $sItem = $(this).closest('.inner').find('select').last().find('option:selected');

    var fYear = parseInt($fItem.attr('data-year')),
    fMonth = parseInt($fItem.attr('data-month')) - 1,
    sYear = parseInt($sItem.attr('data-year')),
    sMonth = parseInt($sItem.attr('data-month')) - 1;

    compareMonths(fYear, fMonth, sYear, sMonth);
    });
    $('#btnSelectCompareYears').bind('click', function (e) {
    $(chartElement).empty();
    $('.carbon-container').hide();

    var $fItem = $(this).closest('.inner').find('select').first().find('option:selected'),
    $sItem = $(this).closest('.inner').find('select').last().find('option:selected');

    var fYear = parseInt($fItem.attr('data-year')),
    sYear = parseInt($sItem.attr('data-year'));

    compareYears(fYear, sYear);
    });

    $('ul.nav li a').bind('click', function (e) {
    e.stopPropagation();
    e.preventDefault();

    $('ul.nav li').removeClass('active');
    $(this).parent().addClass('active');

    $('.statistics-box .inner').hide();
    $($('#' + $(this).attr('data-action'))).closest('.inner').show();

    if ($(this).attr('data-action') == 'lastWeek') {
    $(chartElement).empty();
    $('.carbon-container').hide();
    loadLastWeekData();
    }
    if ($(this).attr('data-action') == 'month') {
    $(chartElement).empty();
    $('.carbon-container').hide();

    var today = new Date();
    var aWeekAgo = new Date();
    aWeekAgo.setMonth(today.getMonth() - 1);

    loadChartData(aWeekAgo, today, function (data) {

    var fmt = [],
    carbon = 0;
    fmt.push(['Datum', 'Effekt i kWh']);
    $.each(data, function () {
    carbon += parseInt(this.carbon);
    fmt.push([headerAsDayInMonth(this.date), parseInt(this.output)]);
    });

    drawChart(fmt, $('#month'), carbon, true);

    });
    }
    if ($(this).attr('data-action') == 'compareMonths') {
    $(chartElement).empty();
    $('.carbon-container').hide();
    }
    });

    };

    var headerAsDayOfWeek = function (str_date) {
    var date = new Date(str_date);
    return weekDayNames[date.getDay()];
    };
    var headerAsDayInMonth = function (str_date) {
    var date = new Date(str_date);
    return date.getDate() + "/" + (date.getMonth() + 1);
    };
    var headerAsMonthName = function (str_date) {
    var date = new Date(str_date);
    return monthNames[date.getMonth()];
    }

    var loadLastWeekData = function () {
    var today = new Date();
    var aWeekAgo = new Date();
    aWeekAgo.setDate(today.getDate() - 6);

    loadChartData(aWeekAgo, today, function (data) {

    var fmt = [],
    carbon = 0;
    fmt.push(['Datum', 'Produktion i kWh']);
    $.each(data, function () {
    carbon += parseInt(this.carbon);
    fmt.push([headerAsDayOfWeek(this.date), parseInt(this.output)]);
    });
    drawChart(fmt, $('#lastWeek'), carbon, true);

    });
    };

    google.load('visualization', '1.0', { 'packages': ['corechart'] });
    google.setOnLoadCallback(loadLastWeekData);

    var compareYears = function (first_year, second_year) {

    var from_first = new Date(first_year, 0),
    to_first = new Date(parseInt(first_year + 1), 0, 0),
    from_second = new Date(second_year, 0),
    to_second = new Date(parseInt(second_year + 1), 0, 0);

    var STATUS_COMPLETE = 2,
    CURRENT_STATUS = 0,
    pushChartData = function (data_first, data_second) {

    var fmt = [];
    fmt.push(['Månad', "År " + first_year, "År " + second_year]);

    var first_last = parseInt(data_first[0].date.split('-')[1]),
    second_last = parseInt(data_second[0].date.split('-')[1]);

    var append_to_first = [],
    append_to_second = [];
    if (first_last > 1) {
    for (var i = 1; i 1) {
    for (var i = 1; i < second_last; i++) {
    append_to_second.push({ date: first_year + "-" + i, output: 0 });
    }
    }
    data_first = append_to_first.concat(data_first);
    data_second = append_to_second.concat(data_second);

    for (var i = 0; i to_second.getDate() ? to_first.getDate() : to_second.getDate();
    for (var i = 0; i < last_day; i++) {

    var f1 = 0,
    f2 = 0;

    if (data_first[i]) {
    date = data_first[i].date;
    f1 = parseInt(data_first[i].output);
    }

    if (data_second[i]) {
    date = data_second[i].date;
    f2 = parseInt(data_second[i].output);
    }

    fmt.push([headerAsDayInMonth(date), f1, f2]);
    }

    drawChart(fmt, $('#compareMonths'));

    };

    var state = {
    'm1': null,
    'm2': null
    };

    $.ajax({
    'url': '/wind-data/',
    'type': 'get',
    'data': {
    'from': dateToQueryString(from_first),
    'to': dateToQueryString(to_first)
    },
    'success': function (data) {
    state.m1 = data;

    if (++CURRENT_STATUS == STATUS_COMPLETE) {
    pushChartData(state.m1, state.m2);
    }
    }
    });

    $.ajax({
    'url': '/wind-data/',
    'type': 'get',
    'data': {
    'from': dateToQueryString(from_second),
    'to': dateToQueryString(to_second)
    },
    'success': function (data) {
    state.m2 = data;

    if (++CURRENT_STATUS == STATUS_COMPLETE) {
    pushChartData(state.m1, state.m2);
    }
    }
    });

    };

    var loadChartData = function (from, to, fn) {

    $.ajax({
    'url': '/wind-data/',
    'type': 'get',
    'data': {
    'from': dateToQueryString(from),
    'to': dateToQueryString(to)
    },
    'success': fn
    });

    };

    var drawChart = function (data, $target, carbon, hideLegend) {

    $(chartElement).appendTo($target);

    var table = new google.visualization.arrayToDataTable(data);
    var chart = new google.visualization.ColumnChart(chartElement);
    chart.draw(table, {backgroundColor: { fill: "#EEEEEE" }, legend: !!hideLegend ? 'none' : '' });

    if (!!carbon) {
    $('.carbon-container .data-value').html(carbon + "");
    $('.carbon-container').show();
    }
    };