/*
  Weer.cpp
  Copyright (c) 2014 Kenneth van Ewijk.  All right reserved.
*/

// include this library's description file
#include "Weer.h"
#include <stdlib.h>
#include <math.h>
#define _USE_MATH_DEFINES

Weer::Weer(void)
{
  // initialize this instance's variables
  min = 0;
  newdag = 0;
  dag = 0;
  rd = 0;
  rd2 = 0;
  amp = 0;
  outsideTemp = 0;
  eq = 0;
}

void Weer::setTemp(double givenTemp)
{
  outsideTemp = givenTemp;
}

void Weer::calcTemp(int timer){
  min = timer;
  newdag = floor(min / 3600) + 1;

  if(newdag > dag){
    rd = ((double) rand() / (RAND_MAX));
    rd2 = round(rd * 5);
    dag = newdag;

    eq = 9- ((1/6) * dag) + rd2;
    amp = (rd * 9) + 3;
  }

  outsideTemp = eq + (amp * sin( ((2 * M_PI) / 3600) * (min - 900)) );
}

double Weer::getTemp(void)
{
  return outsideTemp;
}

