Having some problems with the API and it showing an invalid date. The script is charting everything correctly which is baffling.
Data set:
{
"set_one": [
[1432872000000, -0.628],
[1432785600000, -0.07],
[1432699200000, 0.868],
[1432612800000, -1],
[1432267200000, -0.202],
[1432180800000, 0.248],
[1432094400000, -0.091],
[1432008000000, -0.076],
[1431921600000, 0.372],
[1431662400000, 0.031],
[1431576000000, 0.979],
[1431489600000, -0.054],
[1431403200000, -0.178],
[1431316800000, -0.485],
[1431057600000, 1.139],
[1430971200000, 0.386],
[1430884800000, -0.533],
[1430798400000, -1.103],
[1430712000000, 0.202],
[1430452800000, 0.997],
[1430366400000, -0.955],
[1430280000000, -0.267],
[1430193600000, 0.304],
[1430107200000, -0.491],
[1429848000000, 0.231],
[1429761600000, 0.271],
[1429675200000, 0.461],
[1429588800000, -0.263],
[1429502400000, 0.779],
[1429243200000, -1.023],
[1429156800000, -0.046],
[1429070400000, 0.419],
[1428984000000, 0.17],
[1428897600000, -0.458],
[1428638400000, 0.503],
[1428552000000, 0.474],
[1428465600000, 0.239],
[1428379200000, -0.215],
[1428292800000, 0.76],
[1427947200000, 0.336],
[1427860800000, -0.385],
[1427774400000, -0.778],
[1427688000000, 1.066],
[1427428800000, 0.255],
[1427342400000, -0.184],
[1427256000000, -1.543],
[1427169600000, -0.593],
[1427083200000, -0.17],
[1426824000000, 0.847],
[1426737600000, -0.45],
[1426651200000, 1.278],
[1426564800000, -0.304],
[1426478400000, 1.249],
[1426219200000, -0.542],
[1426132800000, 1.21],
[1426046400000, -0.218],
[1425960000000, -1.552],
[1425873600000, 0.346],
[1425618000000, -1.421],
[1425531600000, 0.119],
[1425445200000, -0.437],
[1425358800000, -0.378],
[1425272400000, 0.576]
],
"set_two": [
[1432872000000, -46.154],
[1425272400000, 22.222]
]
}
I converted everything to milliseconds and am still having this problem. Anyone have any ideas as to why this set wouldn't work?
THANK YOU!
Related
var a = [{'answers' : [{'text':'Cloud','score':10},],},];
main()
{
print(a[0]['answers']);
}
I want to print number 10 in 'score'
Anyone help me fix code !!!
Thanks first !!!
Your problem is properly null-safety which complains about using the value from ['answers']. The reason is that the [] operator on Map returns a nullable type because the result can be null in case that the element does not exist in the Map.
I have in the following used ! to promise the compiler that you are sure that the element does exist in the Map so it stops complaining. But it will insert a check on runtime and crash your application in case the returned value is null:
var a = [
{
'answers': [
{'text': 'Cloud', 'score': 10},
],
},
];
void main() {
print(a[0]['answers']![0]['score']); // 10
}
I’m new to telegraf and influxdb, and currently looking forward to exploring telegraf, but unfortunetly, I have some difficulty getting started, I will try to explain my problem below:
Objectif: parsing JSON file using telegraf input plugin.
Input : https://wetransfer.com/downloads/0abf7c609d000a7c9300dc20ee0f565120200624164841/ab22bf ( JSON file used )
The input json file is a repetition of the same structure that starts from params and ends at it.
you find below the main part of the input file :
{
"events":[
{
"params":[
{
"name":"element_type",
"value":"Home_Menu"
},
{
"name":"element_id",
"value":""
},
{
"name":"uuid",
"value":"981CD435-E6BC-01E6-4FDC-B57B5CFA9824"
},
{
"name":"section_label",
"value":"HOME"
},
{
"name":"element_label",
"value":""
}
],
"libVersion":"4.2.5",
"context":{
"locale":"ro-RO",
"country":"RO",
"application_name":"spresso",
"application_version":"2.1.8",
"model":"iPhone11,8",
"os_version":"13.5",
"platform":"iOS",
"application_lang_market":"ro_RO",
"platform_width":"320",
"device_type":"mobile",
"platform_height":"480"
},
"date":"2020-05-31T09:38:55.087+03:00",
"ssid":"spresso",
"type":"MOBILEPAGELOAD",
"user":{
"anonymousid":"6BC6DC89-EEDA-4EB6-B6AD-A213A65941AF",
"userid":"2398839"
},
"reception_date":"2020-06-01T03:02:49.613Z",
"event_version":"v1"
}
Issue : Following the documentation, I tried to define a simple telegraf.conf file as below:
[[outputs.influxdb_v2]]
…
[[inputs.file]]
files = ["/home/mouhcine/json/file.json"]
json_name_key = "My_json"
#... Listing all the string fields in the json.(I put only these for simplicity reason).
json_string_fields = ["ssid","type","userid","name","value","country","model"]
data_format = "json"
json_query= "events"
Basically declaring string fields in the telegraf.conf file would do it, but I couldn’t get all the fields that are subset in the json file, like for example what’s inside ( params or context ).
So finally, I get to parse fields with the same level of hierarchy as ssid, type, libVersion, but not the ones inside ( params, context, user).
Output : Screen2 ( attachment ).
OUTPUT
By curiosity, I tried to test the documentation’s example, in order to verify whether I get the same expected result, and the answer is no :/, I don’t get to parse the string field in the subset of the file.
The doc’s example below:
Input :
{
"a": 5,
"b": {
"c": 6,
"my_field": "description"
},
"my_tag_1": "foo",
"name": "my_json"
}
telegraf.conf
[[outputs.influxdb_v2]]
…
[[inputs.file]]
files = ["/home/mouhcine/json/influx.json"]
json_name_key = "name"
tag_keys = ["my_tag_1"]
json_string_fields = ["my_field"]
data_format = "json"
Expected Output : my_json,my_tag_1=foo a=5,b_c=6,my_field="description"
The Result I get : "my_field" is missing.
Output: Screen 1 ( attachement ).
OUTPUT
By the way, I use the influxdb cloud 2, and I apologize for the long description of this little problem, I would appreciate some help please :), Thank you so much in advance.
I would like to hide a given column in a google spreadsheet through the API v4, but I struggle to do so.
Does anyone know if it's possible and has managed to do it?
We have in the Apps Script a dedicated method to do so, and I would be surprised if this feature is not available in the REST API.
Yes, there is. It's just not very straightforward.
Here is an example of hiding column 5:
import httplib2
from apiclient.discovery import build
credentials = get_credentials() ## See Google's Sheets Docs
http = credentials.authorize(httplib2.Http())
service = build('sheets', 'v4', http=http)
spreadsheet_id = '#####################'
sheet_id = '#######'
requests = []
requests.append({
'updateDimensionProperties': {
"range": {
"sheetId": sheet_id,
"dimension": 'COLUMNS',
"startIndex": 4,
"endIndex": 5,
},
"properties": {
"hiddenByUser": True,
},
"fields": 'hiddenByUser',
}})
body = {'requests': requests}
response = service.spreadsheets().batchUpdate(
spreadsheetId=spreadsheet_id,
body=body
).execute()
I'm working with this simple chart:
https://jsfiddle.net/w7uyghqn/2/
My dates are in the format: Date(1447793679000), which translates correctly to Thu Aug 11 2016 10:26:59 GMT-0400 (EDT).
var seriesOptions = [
{
"data":[
[Date(1447793679000), 7.8494623656],
[Date(1450913358000), 5.4140127389],
[Date(1460475392000), 6.015037594],
[Date(1460648544000), 3.75],
[Date(1460753244000), 2.1015761821],
[Date(1460985174000), 3.0141843972],
[Date(1460988174000), 5.2264808362],
[Date(1461874589000), 1.5100671141]
],
"name":"Product 1"
},
{
"data":[
[Date(1450729647000), 2.9850746269],
[Date(1452184898000), 4.1666666667],
[Date(1454616863000), 4.1749502982],
[Date(1455206741000), 2.6717557252],
[Date(1458062356000), 2.4],
[Date(1459868909000), 3.8461538462],
[Date(1459882015000), 3.3955857385],
[Date(1459968893000), 4.1832669323],
[Date(1460574864000), 4.973357016],
[Date(1460665314000), 5.2032520325]
],
"name":"Product 2"
}
]
However, as you can see on the x-axis, this is all Jan 1st 1970. Can anyone spot what's wrong?
I've tried so many different formats and I'm totally tearing my hair out.
As jlbriggs said in the comments, you can simply remove the Date() function and use the actual number which will automatically be interpreted by HighCharts as the number of milliseconds since January 1, 1970 because you told it that the xAxis.type is datetime.
I modified your JSFiddle and fixed the problem so you can see it: Working JSFiddle
var seriesOptions = [
{
"data":[
[1447793679000, 7.8494623656],
[1450913358000, 5.4140127389],
[1460475392000, 6.015037594],
[1460648544000, 3.75],
[1460753244000, 2.1015761821],
[1460985174000, 3.0141843972],
[1460988174000, 5.2264808362],
[1461874589000, 1.5100671141]
],
"name":"Product 1"
},{
"data":[
[1450729647000, 2.9850746269],
[1452184898000, 4.1666666667],
[1454616863000, 4.1749502982],
[1455206741000, 2.6717557252],
[1458062356000, 2.4],
[1459868909000, 3.8461538462],
[1459882015000, 3.3955857385],
[1459968893000, 4.1832669323],
[1460574864000, 4.973357016],
[1460665314000, 5.2032520325]
],
"name":"Product 2"
}
]
I'm pulling some data from a database that I'm trying to render into a Highcharts stock chart. The data is pulled from the database with PHP and passed to the chart with a $.get(..php/line-data.php) call, and the data retrieved is supposed to be the data that is rendered on the chart.
The data is being returned in the following manner, and I have verified this by logging data in the console. It appears as such, with the first value being the UNIX-to-Javascript converted date/time (x-axis), and the second being the value (y-axis):
[[1362639600000, 8],[1362726000000, 20],[1362985200000, 28],[1363071600000, 51],[1363158000000, 64],[1363244400000, 11],[1363330800000, 4],[1363503600000, 4],[1363590000000, 21],[1363676400000, 10],[1363762800000, 31],[1363849200000, 13],[1363935600000, 17],[1364194800000, 10],[1364454000000, 1],[1365058800000, 30],[1365145200000, 10],[1366009200000, 55],[1366182000000, 18],[1366268400000, 22],[1366354800000, 12]]
As an experiment, I tried just plugging this data straight into a basic demo Fiddle, and it seems to render fine.
FIDDLE HERE.
So what am I doing incorrectly? Everything seems to be set up correctly, but it's not rendering. This is what I see:
Here are the relevant portions of my code. Yes, I know that mysql_* is deprecated...I'll change it.
$.get('../php/line-data.php', function(data) {
window.chart = new Highcharts.StockChart({
chart : {
renderTo : 'total_mentions',
margin: [20, 10, 10, 10],
spacingTop: 0,
spacingBottom: 1,
spacingLeft: 0,
spacingRight: 0
},
series : [{
name : 'Total Mentions',
data: data,
type:'line',
lineWidth:1,
shadow:false,
states: {
hover: {
lineWidth:1
}
},
id : 'dataseries',
tooltip : {
valueDecimals: 4,
borderColor:'#DA7925',
borderRadius: 0,
borderWidth: 1,
shadow: false
},
color:'#DA7925',
fillOpacity:0.2
}]
[more options...etc.]
No problems with this code. It's pulling the correct data and echoing how I expect it to.
<?php
$expAddress = "URL";
$expUser = "USERNAME";
$expPwd = "PASSWORD";
$database = "DB";
$db = mysql_connect($expAddress, $expUser, $expPwd);
mysql_select_db($database, $db);
$ok = mysql_query("
SELECT
DATE(created_at) AS create_date,
COUNT(id) AS total
FROM
tweets
WHERE
subject LIKE 'word1'
OR
subject LIKE 'word2'
GROUP BY
DATE(created_at)");
if (!$ok) {
echo "<li>Mysql Error: ".mysql_error()."</li>";
}
else {
while($row = mysql_fetch_assoc($ok)){
extract($row);
$date = strtotime($create_date);
$date *= 1000;
$data[] = "[$date, $total]";
}
$tmp = join($data,',');
echo "[".$tmp."]";
}
?>
Have you tried parsing your data (string) into a javascript object before setting it to the series[i].data?
series : [{
data: JSON.parse(data)
}]
What you are getting from php through $.get is basically string and NOT a javascript array of array of numbers, which is what you want. It may look like that, but it is as simple as "5"!=5, but parseInt("5")==5 same is the case with json objects, you need to parse the string into such an object before javascript or highcharts can interpret it correctly, highcharts could do it on your behalf, but it is not designed that way.
Try his fiddle to get an idea of the data types in picture
var data="[[1362639600000, 8],[1362726000000, 20],[1362985200000, 28],[1363071600000, 51],[1363158000000, 64],[1363244400000, 11],[1363330800000, 4],[1363503600000, 4],[1363590000000, 21],[1363676400000, 10],[1363762800000, 31],[1363849200000, 13],[1363935600000, 17],[1364194800000, 10],[1364454000000, 1],[1365058800000, 30],[1365145200000, 10],[1366009200000, 55],[1366182000000, 18],[1366268400000, 22],[1366354800000, 12]]"
console.log(typeof data); //string
var parsedData=JSON.parse(data);
console.log(typeof parsedData); //object
console.log(typeof parsedData[0]); //object [1362639600000, 8]
console.log(typeof parsedData[0][0]); //number 1362639600000
When you paste the console value directly in the fiddle, you are actually pasting it as a valid javascript array, try using your console value wrapped by " quotes " and see that the exact issue is reproduced!!
Demo # jsFiddle
An alternate approach could be using the $.getJSON() method instead. jQuery does the parsing for you before it calls your callback method
Your problem is in either the output from the PHP script or when you receive the data in your Javascript (quite obvious).
First, don't do JSON by hand use json_encode (http://php.net/manual/en/function.json-encode.php). It's easier and it will guarantee that strings will be escaped properly.
Secondly, inspect your data variable with a debugger. You could also post the exact content of the variable to the question.
But basically, as long as it is working in the fiddle and not in your program you have not yet reproduced the error in your code properly in the fiddle.
For instance, you could replace data in your callback with the data you have in your fiddle to see if the code runs.