Pentaho javacriot code variable object - pentaho
I am trying to navigate my object with the response of my rest client method, this response is theoretically a JSON Object such that.
{"457": {"2": {"value": "53.8", "timestamp": 1534257707}, "3": {"value": "21.9", "timestamp": 1534257707}, "4": {"value": "255.0", "timestamp": 1534257707}, "21": {"value": "996.0", "timestamp": 1534257707}, "1": {"value": "4.15", " timestamp ": 1534257707}," 17 ": {" value ":" 156.99062499999997 "," timestamp ": 1534257707}," 5 ": {" value ":" 37.667 "," timestamp ": 1534257707}," 6 ": {"value": "28.900000000000002", "timestamp": 1534257707}, "8": {"value": "4.28", "timestamp": 1534257707}, "15": {"value": "0.83", " timestamp ": 1534257707}," 10 ": {" value ":" 19.31 "," timestamp ": 1534257707}," 22 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 23 ": {"value": "0.0", "timestamp": 1534257707}, "24": {"value": "0.0", "timestamp": 1534257707}, "26": {"value": "0.0", " timestamp ": 1534257707}," 653 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 657 ": {" value ":" - 98.0 "," timestamp ": 1518420299}," 43 " : {"value": "11.824136243472958", "timestamp": 1534257707}, "42": {"value": "326.54049999999995", "timestamp": 1534257707}}}
I have created a component in JavaScript to process this data:
This is my code in java script and it works correctly, since I have tried it programming it in another environment.
var key = Object.keys (data) [0];
var finalobj = {};
for (var and in data [key]) {
finalobj [e] = {
type: "float"
, value: parseFloat (data [key] [e] .value)
, metadata: {
timestamp: {
value: parseInt (data [key] [e] .timestamp)
, type: "Integer"
}
}
};
}
The problem is that if I assign to the field it dates the value of my answer like this:
var data = result_ult_dat;
When I throw the code it does not work, but if I manually assign the code to it, if it works correctly, what is the problem ?, I do not understand it, the value of result_ult_dat is the same as the one that I copied, it has to be transforming or something like this:
var data = {"457": {"2": {"value": "53.8", "timestamp": 1534257707}, "3": {"value": "21.9", "timestamp": 1534257707}, " 4 ": {" value ":" 255.0 "," timestamp ": 1534257707}," 21 ": {" value ":" 996.0 "," timestamp ": 1534257707}," 1 ": {" value ":" 4.15 "," timestamp ": 1534257707}," 17 ": {" value ":" 156.99062499999997 "," timestamp ": 1534257707}," 5 ": {" value ":" 37.667 "," timestamp ": 1534257707}," 6 ": {" value ":" 28.900000000000002 "," timestamp ": 1534257707}," 8 ": {" value ":" 4.28 "," timestamp ": 1534257707}," 15 ": {" value ":" 0.83 "," timestamp ": 1534257707}," 10 ": {" value ":" 19.31 "," timestamp ": 1534257707}," 22 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 23 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 24 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 26 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 653 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 657 ": {" value ":" - 98.0 "," timestamp ": 1518420299}, "43": {"value": "11.824136243472958", "timestamp": 1534257707}, "42": {"value": "326.54049999999995", "timestamp": 1534257707}}};
How can I fix the problem.
My complete code is this:
Thank you very much.
Edit01
This is my complete design, as you can see the value of data is the same as the response of my http client.
answer if I pass it by variable
the funny thing is that JSONOutPut is {} when it would have to be the for transformation.
And when I try to put as such the answer in the data variable if it works, look.
I do not understand why
I have solved it by adding this to my javascript code and working with object
var object = JSON.parse (result_ult_dat);
Related
How do I move the position of the player based on user input. (Represented by O). Code I have written So far. Pls answer in vb
Module Program Dim startx As Integer Dim starty As Integer Dim endx As Integer Dim endy As Integer Dim maze As String(,) = { {"x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x"}, {"O ", " ", " ", " ", " ", " ", " ", " ", " ", "x"}, {"x ", "x ", "x ", "x ", "x ", " ", "x ", "x ", " ", "x"}, {"x ", "x ", " ", "x ", "x ", " ", "x ", "x ", " ", "x"}, {"x ", "x ", " ", " ", " ", " ", "x ", "x ", " ", "x"}, {"x ", "x ", "x ", "x ", "x ", " ", "x ", "x ", "x ", "x"}, {"x ", " ", " ", " ", " ", " ", " ", " ", " ", "x"}, {"x ", " ", "x ", "x ", "x ", "x ", "x ", "x ", " ", "x"}, {"x ", " ", " ", " ", " ", "x ", "x ", "x ", " ", " "}, {"x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x"}} Sub Main(args As String()) Console.WriteLine("This is a maze game") Console.WriteLine("Please enter where you want to go (x and y cordinate)") start displaychessboard() End Sub Sub displaychessboard() Console.WriteLine(" 0 1 2 3 4 5 6 7 8 9") For x As Integer = 0 To 9 Console.Write(x & " ") For y As Integer = 0 To 9 Console.Write(maze(x, y)) Next Console.WriteLine() Next End Sub Sub makemove() End Sub End Module
How do I move the position of the player based on user input. You store the position of a player in one or more variables. Since you have a two-dimensional maze, you can use a two-element tuple or, for simplicity, a player_x and a player_y variable. When the user provides input, you modify the variables accordingly. For example, "moving left" would decrease player_x by one. When drawing your maze, you look at the current values of player_x and player_y. If they match the current position in your loop, you output "O" instead of a space. Pls answer in vb The Stack Overflow community will gladly help you understand concepts and teach you how to improve your Visual Basic skills, but we are not a "here is my task, you write code" service.
Reading Code From a Text File Efficiently And How to Distinguish Blocks of Code In The Text File
I'm creating a utility for a game that creates spreadsheets of data by reading the game's code. One of the most basic aspects of this is being able to read the game's code efficiently. The game is written in C#. I'm using VB.Net for my program because my mind can't grasp the abstraction of more complex languages. Historically the way I had my program recognise code blocks in the code text file is by counting the brackets that encapsulated them and working off of that. This seems a bit clunky, though. Is there any simpler way to help the program figure out code blocks? For Example, code in the text file might look like this: 6673={ key="d_example_duchy_1" de_facto_liege=12 variables={ data={ { flag="traditional_de_jure_kingdom" tick=0 data={ type=lt identity=6632 } } } } de_jure_liege=6632 de_jure_vassals={ 6674 6678 6682 6686 } holder=558 name="Example Duchy 1" date=1253.1.1 heir={ 880 } history={ 1253.1.1=558 } capital=6674 history_government="tribal_government" coat_of_arms_id=2320 } 6674={ key="c_example_county_1" variables={ data={ { flag="influx_culture" tick=0 data={ type=culture identity=11 } } { flag="influx_faith" tick=0 data={ type=faith identity=57 } } { flag="fog_resistance" tick=0 data={ type=value } } } } de_jure_liege=6673 de_jure_vassals={ 6675 6676 6677 } holder=558 name="Example County 1" date=1243.6.26 heir={ 880 } capital=6674 coat_of_arms_id=2323 } 6675={ key="b_example_barony_1" de_facto_liege=6674 de_jure_liege=6674 holder=558 name="Example Barony 1" date=1254.1.1 capital_barony=yes duchy_capital_barony=yes capital=6674 coat_of_arms_id=2328 } 6676={ key="b_example_barony_2" de_facto_liege=6674 de_jure_liege=6674 holder=11609 name="Example Barony 2" date=1253.7.28 capital=6674 coat_of_arms_id=2332 } 6677={ key="b_example_barony_3" de_facto_liege=6674 de_jure_liege=6674 holder=558 name="Example Barony 3" date=1232.2.8 heir={ 880 } capital=6674 theocratic_lease=yes coat_of_arms_id=2334 } Thanks in advance. :)
The solution I eventually settled on, for discerning the overall code-blocks (e.g. all the data nested under 6674={ ... }) was basically: Dim Code As String = File.ReadAllText("PATH/TO/CODE/FILE.txt") Dim Output As List(Of String) = Code.Split(vbCrLf & "}" & vbCrLf).ToList So in plain English, reading all the code into a single string, then splitting the string according to how the original code's language distinguished the initial nest of code (i.e. a carriage return followed by a curly bracket followed by another carriage return). The list at the end would look something like this: Output(0) 6673={" & vbCrLf & " key=""d_example_duchy_1""" & vbCrLf & " de_facto_liege=12" & vbCrLf & " variables={" & vbCrLf & " data={ {" & vbCrLf & " flag=""traditional_de_jure_kingdom""" & vbCrLf & " tick=0" & vbCrLf & " data={" & vbCrLf & " type=lt" & vbCrLf & " identity=6632" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " de_jure_liege=6632" & vbCrLf & " de_jure_vassals={ 6674 6678 6682 6686 }" & vbCrLf & " holder=558" & vbCrLf & " name=""Example Duchy 1""" & vbCrLf & " date=1253.1.1" & vbCrLf & " heir={ 880 }" & vbCrLf & " history={ 1253.1.1=558 }" & vbCrLf & " capital=6674" & vbCrLf & " history_government=""tribal_government""" & vbCrLf & " coat_of_arms_id=2320 Output(1) 6674={" & vbCrLf & " key=""c_example_county_1""" & vbCrLf & " variables={" & vbCrLf & " data={ {" & vbCrLf & " flag=""influx_culture""" & vbCrLf & " tick=0" & vbCrLf & " data={" & vbCrLf & " type=culture" & vbCrLf & " identity=11" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " {" & vbCrLf & " flag=""influx_faith""" & vbCrLf & " tick=0" & vbCrLf & " data={" & vbCrLf & " type=faith" & vbCrLf & " identity=57" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " {" & vbCrLf & " flag=""fog_resistance""" & vbCrLf & " tick=0" & vbCrLf & " data={" & vbCrLf & " type=value" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " de_jure_liege=6673" & vbCrLf & " de_jure_vassals={ 6675 6676 6677 }" & vbCrLf & " holder=558" & vbCrLf & " name=""Example County 1""" & vbCrLf & " date=1243.6.26" & vbCrLf & " heir={ 880 }" & vbCrLf & " capital=6674" & vbCrLf & " coat_of_arms_id=2323 And so on with the remaining three.
2d array of generic length in a class
I have a class that currently works like this. Class Maze Public board(10, 10) As Object Dim maze1 As New Maze With {.board = {{" ", " ", "X", "X", " ", "X", "X", "X", " ", "X"}, {"X", " ", " ", " ", " ", "X", " ", " ", " ", "X"}, {" ", " ", "X", " ", "X", " ", " ", " ", " ", "X"}, {"X", " ", "X", " ", " ", "X", "X", "X", " ", " "}, {"X", " ", "X", "X", " ", " ", " ", " ", "X", " "}, {" ", "X", " ", " ", "X", " ", " ", "X", " ", " "}, {" ", "X", "X", " ", "X", " ", " ", " ", " ", "X"}, {" ", " ", " ", " ", " ", "X", "X", " ", " ", "X"}, {"X", "X", " ", "X", " ", " ", " ", "X", " ", " "}, {" ", " ", " ", "X", "X", " ", " ", " ", "X", " "}}} However I cant find away to remove the prespecified length without methods such as GetLength now not working.
In the .Net world, if you define a type as Object you're almost always doing something very wrong you will soon come to regret. In this case, it looks like String may be more appropriate. However, perhaps based on how this is used later it might turn out that Integer or a specific class type could be better, alongside a special method to translate this into text or graphics for output. Moving on to the specific issue of size... consider a List: Class Maze Dim board As List(Of List(Of String)) board = New List(Of List(Of string)) From { New List(Of String) From {" ", " ", "X", "X", " ", "X", "X", "X", " ", "X"}, New List(Of String) From {"X", " ", " ", " ", " ", "X", " ", " ", " ", "X"}, New List(Of String) From {" ", " ", "X", " ", "X", " ", " ", " ", " ", "X"}, New List(Of String) From {"X", " ", "X", " ", " ", "X", "X", "X", " ", " "}, New List(Of String) From {"X", " ", "X", "X", " ", " ", " ", " ", "X", " "}, New List(Of String) From {" ", "X", " ", " ", "X", " ", " ", "X", " ", " "}, New List(Of String) From {" ", "X", "X", " ", "X", " ", " ", " ", " ", "X"}, New List(Of String) From {" ", " ", " ", " ", " ", "X", "X", " ", " ", "X"}, New List(Of String) From {"X", "X", " ", "X", " ", " ", " ", "X", " ", " "}, New List(Of String) From {" ", " ", " ", "X", "X", " ", " ", " ", "X", " "} } Now you can add a line to end like so: board.Add(New List(Of String) From {" ", "X", " ", " ", " " ... }) Or add a column like this: For Each c As List(Of String) In board c.Add(" ") Next
This allows you to have 2d array without specifying length explicitly Public board(,) As Object = {}
Link in an email (DoCmd.SendObject)
I generate an email in an application access in vba. At the end I wish to put a hyperlink but the email is in raw and not in html. Do you have a solution? DoCmd.SendObject , , , "adressmail#hotmail.com", "", "", " " & Types & " de " & Prenom & " " & Nom & " prend effet le " & Effet_au & "", "Madame, Monsieur," & vbCrLf & vbCrLf & "texte" & **"LINK HERE"** & vbCrLf, True, ""
You can change the email to HTML by setting the format in the third parameter to acFormatHTML. This will mean that the entire email message will have to be in HTML however.
Getting system outofmemoryexception building string in vb
I have a dataset that is with arround 30000records, so loping inside it and building the string fileStavki trows exeption, systemoutofmemmory. How can i solve this. Is working with arrays possible solution or something else? Dim sb As New StringBuilder For Each inRow In ds_in.Tables(0).Rows rbr += 1 pisi_red = "2" & Enc3.prefill(rbr, "0", 6) & Share.RightPrefill(inRow("prioritet"), "0", 5) pisi_red &= Enc3.prefill(Enc3.IsNull(inRow("smetka_davac"), "0"), "0", 15) pisi_red &= Share.RightPrefill(Enc3.lat2kir(Enc3.IsNull(inRow("naziv_davac"), "")), " ", 70) pisi_red &= Share.RightPrefill(Enc3.IsNull(inRow("povik_broj_davac"), ""), " ", 24) pisi_red &= Share.RightPrefill(Enc3.lat2kir(Enc3.IsNull(inRow("cel_na_doznaka"), "")), " ", 70) pisi_red &= Enc3.prefill(inRow("sif_tip_plakanje"), "0", 6) pisi_red &= "+" & Enc3.prefill(FormatNumber(inRow("iznos"), 5, TriState.False, TriState.False, TriState.False), "0", 21) pisi_red &= inRow("smetka_primac") & Share.RightPrefill(Enc3.lat2kir(Trim(inRow("naziv_primac"))), " ", 70) pisi_red &= Share.RightPrefill(Enc3.IsNull(inRow("povik_broj_primac"), ""), " ", 24) pisi_red &= inRow("tip_instrument") & Share.RightPrefill(Enc3.IsNull(inRow("broj_transakcija"), ""), " ", 16) pisi_red &= inRow("sistem_poravnuva") & Enc3.prefill(Enc3.IsNull(inRow("edb"), ""), "0", 13) pisi_red &= vbCrLf sb.Append(pisi_red) 'fileStavki &= pisi_red Next after this i have sw.Write(fileStavki) sw.Flush() sw.Close() I think even if i use stringbuilder the string fileStavki will be build like this filestavki = sb.ToString And here i will also get outofmemory exeption