<commit_before><?php

use App\SensorData;

function getSensors(){
    $sensors = [];

    $json = File::get("../database/data/sensors.json");
    $data = json_decode($json);

    foreach ($data as $obj) {
        $sensors[] = $obj;
    }

    return $sensors;
}

function getFilteredData($request)
{
    $nodeId = $request->input('node_id');
    $variable = $request->input('variable');
    $startDate = $request->input('start_date');
    $endDate = $request->input('end_date');

    $startDate = date("YmdHis", strtotime($startDate));
    $endDate = date("YmdHis", strtotime($endDate));

    $sensorData = SensorData::where('node_id', $nodeId)
        ->where('variable', $variable)
        ->whereBetween('data.timestamp', array($startDate, $endDate))
        ->first();

    /*
     * Filter data
     */
    $data = [];

    if($sensorData)
    {
        foreach($sensorData['data'] as $key => $datum)
        {
            if($datum['timestamp'] >= $startDate && $datum['timestamp'] <= $endDate)
            {
                $data[] = $datum;
            }
        }
    }

    /*
     * Sort data
     */
    function cmp($item1, $item2) {
        $ts1 = strtotime($item1['timestamp']);
        $ts2 = strtotime($item2['timestamp']);
        return $ts1 - $ts2;
    }

    usort($data, "cmp");

    $sensorData['data'] = $data;

    return $sensorData;
}

function mapNode($node)
{
    $node['links'] = [
        [<commit_msg>Refactor date format on getFilteredData method<commit_after><?php

use App\SensorData;

function getSensors(){
    $sensors = [];

    $json = File::get("../database/data/sensors.json");
    $data = json_decode($json);

    foreach ($data as $obj) {
        $sensors[] = $obj;
    }

    return $sensors;
}

function getFilteredData($request)
{
    $nodeId = $request->input('node_id');
    $variable = $request->input('variable');

    $sensorData = SensorData::where('node_id', $nodeId)
        ->where('variable', $variable)
        ->first();

    /*
     * Filter data
     */
    $data = [];

    if($sensorData)
    {
        $startDate = $request->input('start_date');
        $endDate = $request->input('end_date');
        $format = 'm/d/Y';

        $from = DateTime::createFromFormat($format, $startDate);
        $to = DateTime::createFromFormat($format, $endDate);

        foreach($sensorData['data'] as $key => $datum)
        {
            $formattedDateTime = DateTime::createFromFormat('m/d/y h:i:s A', $datum['timestamp']);

            if (($from <= $formattedDateTime && $formattedDateTime <= $to) || ($from <= $formattedDateTime->modify('+1 day') && $formattedDateTime <= $to)) {
                $data[] = $datum;
            }
        }
    }

    /*
     * Sort data
     */
    function cmp($item1, $item2)
    {
        $ts1 = strtotime($item1['timestamp']);
        $ts2 = strtotime($item2['timestamp']);
        return $ts1 - $ts2;
    }

//    usort($data, "cmp");

    $sensorData['data'] = $data;

    return $sensorData;
}

function mapNode($node)
{
    $node['links'] = [
        [
{'fraction_non_alphanumeric': 0.18963254593175852, 'fraction_numerical': 0.00557742782152231, 'mean_word_length': 2.4451977401129943, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4403905', 'n_tokens_mistral': 1018, 'n_tokens_neox': 987, 'n_words': 171}