<commit_before>// Copyright (c) 2014 Electric Imp
// This file is licensed under the MIT License
// http://opensource.org/licenses/MIT

const PLOTLY_USER       = "YOUR_USERNAME_HERE";
const PLOTLY_KEY        = "YOUR_APIKEY_HERE";
// Name your plot
const PLOTLY_FILENAME   = "Electric Imp Graph";
// How much historical data to show in hours (autorange must be disabled)
const GRAPH_WINDOW      = 24;

function updatePlotly(temp, lux) {
    local timestamp = time();
    local query = {
        un=PLOTLY_USER,
        key=PLOTLY_KEY,
        origin="plot",
        platform="electricimp",
        // Data
        args=format(@"[{""x"": %i000, ""y"": %f, ""name"": ""Temperature""}, {""x"": %i000, ""y"": %f, ""name"": ""Light Level (lux)"", ""yaxis"": ""y2""}]", timestamp, temp, timestamp, lux),
        // Formatting options
        kwargs=http.jsonencode({
            filename=PLOTLY_FILENAME
            fileopt="extend"
            world_readable="true"
            layout={
                title="Electric Imp Temperature / Light Level Logger"
                xaxis={
                    title="Date"
                    type="date"
                    // Set autorange to false to use GRAPH_WINDOW setting
                    autorange=false
                    range=[format("%i000", timestamp - (GRAPH_WINDOW * 3600)), format("%i000", timestamp)]
                }
                yaxis={
                    title="Temperature (°F)",
                    side="left",
                    autorange=true,
                }
                yaxis2={
                    title="Illuminance (lux)",
                    side="right",
                    overlaying="y",
                    autorange=true,
                }
            }
        })
    }
    local query_encoded = http.urlencode(query);
    local request = http.post("https://plot.ly/clientresp", {}, query_encoded);
    local response = request.sendsync();
    local reply = http.jsondecode(response.body);
    // Display any responses we get from Plotly
    if (reply["message"] != "") {
        server.log(reply["message"]);
    }
    if (reply["warning"] != "") {
        server.log(reply["warning"]);
    }
    if (reply["error"] != "") {
        server.log(reply["error"]);
    }
    server.log("Graph available at " + reply.url);
}

// When we get data from the device, format it and send it to Plotly
device.on("data", function(data) {
    updatePlotly(data.temp, data.lux);
});
<commit_msg>imp003evb logging: changed autorange to true<commit_after>// Copyright (c) 2014 Electric Imp
// This file is licensed under the MIT License
// http://opensource.org/licenses/MIT

const PLOTLY_USER       = "YOUR_USERNAME_HERE";
const PLOTLY_KEY        = "YOUR_APIKEY_HERE";
// Name your plot
const PLOTLY_FILENAME   = "Electric Imp Graph";
// How much historical data to show in hours (autorange must be disabled)
const GRAPH_WINDOW      = 24;

function updatePlotly(temp, lux) {
    local timestamp = time();
    local query = {
        un=PLOTLY_USER,
        key=PLOTLY_KEY,
        origin="plot",
        platform="electricimp",
        // Data
        args=format(@"[{""x"": %i000, ""y"": %f, ""name"": ""Temperature""}, {""x"": %i000, ""y"": %f, ""name"": ""Light Level (lux)"", ""yaxis"": ""y2""}]", timestamp, temp, timestamp, lux),
        // Formatting options
        kwargs=http.jsonencode({
            filename=PLOTLY_FILENAME
            fileopt="extend"
            world_readable="true"
            layout={
                title="Electric Imp Temperature / Light Level Logger"
                xaxis={
                    title="Date"
                    type="date"
                    // Set autorange to false to use GRAPH_WINDOW setting
                    autorange=true
                    range=[format("%i000", timestamp - (GRAPH_WINDOW * 3600)), format("%i000", timestamp)]
                }
                yaxis={
                    title="Temperature (°F)",
                    side="left",
                    autorange=true,
                }
                yaxis2={
                    title="Illuminance (lux)",
                    side="right",
                    overlaying="y",
                    autorange=true,
                }
            }
        })
    }
    local query_encoded = http.urlencode(query);
    local request = http.post("https://plot.ly/clientresp", {}, query_encoded);
    local response = request.sendsync();
    local reply = http.jsondecode(response.body);
    // Display any responses we get from Plotly
    if (reply["message"] != "") {
        server.log(reply["message"]);
    }
    if (reply["warning"] != "") {
        server.log(reply["warning"]);
    }
    if (reply["error"] != "") {
        server.log(reply["error"]);
    }
    server.log("Graph available at " + reply.url);
}

// When we get data from the device, format it and send it to Plotly
device.on("data", function(data) {
    updatePlotly(data.temp, data.lux);
});

{'fraction_non_alphanumeric': 0.14104627766599598, 'fraction_numerical': 0.010261569416498993, 'mean_word_length': 1.886759581881533, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3304494', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1378, 'n_words': 345}