Digit's Values not getting extracted from Dictionary - autohotkey

I have a dictionary that contains Letters and Digits and i can get the values of the letter keys just fine but not the ones from digits even though they're enclosed in " . It isn't important for the question but just in case you're wondering what the bluscream.ahk file that's included looks like: https://github.com/Bluscream/ahk-scripts/blob/master/Lib/bluscream.ahk
I tried what can be seen in the code. I have no idea what to do
; Version 1
; Date 02/02/2019
#Include <bluscream>
#SingleInstance Force
Process Priority,, Below Normal
SetWorkingDir %A_ScriptDir%
#Warn
#Persistent
SetKeyDelay, 150
game_name := "LEGO" ; LEGO Jurassic World
game_title := "ahk_class TTalesWindow" ; ahk_exe LEGOJurassicWorld_DX11.EXE
chars := { "B" : "{Up}", "C" : "{Up 2}", "D" : "{Up 3}", "E" : "{Up 4}", "F" : "{Up 5}", "G" : "{Up 6}", "H" : "{Up 7}", "J" : "{Up 8}", "K" : "{Up 9}", "L" : "{Up 10}", "M" : "{Up 11}", "N" : "{Up 12}", "O" : "{Up 13}", "P" : "{Up 14}", "Q" : "{Up 15}", "R" : "{Up 16}", "S" : "{Down 18}", "T" : "{Down 17}", "U" : "{Down 16}", "V" : "{Down 15}", "W" : "{Down 14}", "X" : "{Down 13}", "Y" : "{Down 12}", "Z" : "{Down 11}", "0" : "{Down 10}", "1" : "{Down 9}", "2" : "{Down 8}", "3" : "{Down 7}", "4" : "{Down 6}", "5" : "{Down 5}", "6" : "{Down 4}", "7" : "{Down 3}", "8" : "{Down 2}", "9" : "{Down}" }
file := "codes.txt"
global noui := false
scriptlog("Started logging here...")
FileRead, LoadedText, %file%
codes := StrSplit(LoadedText, "`n", "`r")
Loop, % codes.MaxIndex()
{
if !(WinActive(game_title)) {
TrayTip, AutoHotKey, Bringing %game_name% to front to enter code...
Sleep, 1000
WinWaitActive, %game_title%
}
code := StrStrip(codes[A_Index])
length := StrLen(code)
FormatTime, timestamp, A_Now, hh:mm:ss
scriptlog("[" . timestamp . "] Now processing code: " . code . " [" . length . "] (`r`n", "", true)
splitted_code := StrSplit(code)
for i, char in splitted_code {
tosend := chars[char]
scriptlog("i:" . i . " char:" . char . " tosend:" . tosend . "`r`n", "", true)
if (tosend){
SendEvent, % tosend
}
if (i < length)
SendInput, {Right}
}
scriptlog(")`r`n","",true)
SendInput, {Enter}
}
Expected results:
[11:17:43] Started logging here...
[11:17:46] Now processing code: 28SPSR [6] (
i:1 char:2 tosend:{Down 8}
i:2 char:8 tosend:{Down 2}
i:3 char:S tosend:{Down 18}
i:4 char:P tosend:{Up 14}
i:5 char:S tosend:{Down 18}
i:6 char:R tosend:{Up 16}
)
Actual Results:
[11:17:43] Started logging here...
[11:17:46] Now processing code: 28SPSR [6] (
i:1 char:2 tosend:
i:2 char:8 tosend:
i:3 char:S tosend:{Down 18}
i:4 char:P tosend:{Up 14}
i:5 char:S tosend:{Down 18}
i:6 char:R tosend:{Up 16}
)

Looks like a bug of the object declaration. A problem about string vs numbers.
Using numbers without quotes removes the problem.
But also, doing this after declaring the object fixes the problem too:
for k,v in chars
chars[k] := v
You could fill a bug on the official board: https://www.autohotkey.com/boards/

Related

Postgres copy to insert data into table

I have a text file in the below format. The first row is the header. The second row is the data.
"A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" "AA" "BB" "CC" "DD" "EE" "FF" "GG" "HH" "II" "JJ" "KK" "LL" "MM" "NN" "OO"
"1019311288593" "3" "3" "3421D" "1" "2" "3" "" "1500188" "201802" "" "" "11" "" "" "" "" "9710" "121598630" "1336332" "60" "20180213" "" "" "" "1" "" "00209500188021318" "" "" "" "" "1215630" "" "" "" "" "" 20180222 "green" 1
I am trying to use the following command to insert this data into a table -
\COPY service(<All columns listed above>) FROM 'test.txt' DELIMITER E'\t' CSV HEADER
But I am getting this error -
`Missing data for column B.`

mongodb $sum all values in object with variable key name

we have the following document
{
"_id" : "F80BBEDE6395",
"up" : {
"10" : NumberLong(1916327),
"11" : NumberLong("4557798933"),
"12" : NumberLong(1057250763),
"13" : NumberLong(10167577),
"14" : NumberLong(9464393),
"15" : NumberLong(10082616),
"16" : NumberLong(9982689),
"17" : NumberLong(8612066),
"18" : NumberLong(193879404),
"19" : NumberLong("4692628921"),
"20" : NumberLong(541674158),
"21" : NumberLong(10482839),
"22" : NumberLong(9671272)
},
"down" : {
"10" : NumberLong(1880514),
"11" : NumberLong("19698709594"),
"12" : NumberLong("28850509901"),
"13" : NumberLong(10073361),
"14" : NumberLong(9283009),
"15" : NumberLong(9533924),
"16" : NumberLong(9605101),
"17" : NumberLong(1398871165),
"18" : NumberLong("34124867465"),
"19" : NumberLong("180468996228"),
"20" : NumberLong("18472208011"),
"21" : NumberLong(10066752),
"22" : NumberLong(9288118)
},
"monthUp" : NumberLong("11113611958"),
"monthDown" : NumberLong("283073893143")
}
up and down are objects, one by day with a counter (day 10 of month, day 11, and so on).
The problem we get is how to in an update, sum all "up" values to "monthUp" and all "down" values to "monthDown"
In this example, the monthUp and monthDown are not ok, since both are not the sum of up / down objects.
This document is build from a hadoop process that updates every item on "up" and "down", since the hadoop job updates the document and we want to avoid a new job to make the "monthDown" and "monthUp" sum, will be very effective and useful for us to do the sum on the same update operation.
Thanks in advance

Sed to replace previous line

I am trying to replace the previous line of a string match.
Example json
"test" : {
"aa" : true,
"ac" : "port",
"tr" : "p2",
"ll" : 90,
"mp" : true
}
If "ll" equals 90, I need to change the previous line to "mu" : "p1". I have tried the below sed but it always replaces the same line instead on the previous line. Please suggest
sed -e '/"ll" : 90/!b;!N;c"mu" : "p1"'
You can try this sed:
sed 'N;/\n *"ll" : 90/{s/^\([^"]*\).*\n/\1"mu" : "p1",\n/;};P;D' file
As suggested by #potong,
sed -r 'N;s/.*(\n(\s*)"ll" : 90,)/\2"mu : "p1",\1/;P;D' file
Output:
"test" : {
"aa" : true,
"ac" : "port",
"mu" : "p1",
"ll" : 90,
"mp" : true
}

MongoDB Text search fails for stop words

I'm trying to do a query in my collection, but its not returning anything.
Here's my query:
{'$match': {'$text': {'$search': 'a'}}},
{'$group': {'_id': {'texto': '$texto'},
'somanumero': {'$sum': '$numero'}}}
My collection:
{ "_id" : ObjectId("555cdc4fe13823315537042d"), "texto" : ObjectId("555cdc4fe13823315537042c"), "numero" : ObjectId("555cdc4fe13823315537042e") }
{ "_id" : ObjectId("555cdc5ee13823315537042f"), "numero" : 5, "texto" : "a", "lattexto" : "-15.79506", "lontexto" : "-47.88322" }
{ "_id" : ObjectId("555cdc6ae138233155370430"), "numero" : 10, "texto" : "a", "lattexto" : "-15.79506", "lontexto" : "-47.88322" }
{ "_id" : ObjectId("555cdc73e138233155370431"), "numero" : 3, "texto" : "b", "lattexto" : "-15.79506", "lontexto" : "-47.88322" }
And here's my text index:
{
"v" : 1,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"name" : "texto_text",
"ns" : "OSA.teste_texto",
"default_language" : "portuguese",
"weights" : {
"texto" : 1
},
"language_override" : "language",
"textIndexVersion" : 2
}
When i use $group or $match alone, it works.
Am I doing something wrong?
From the docs:
MongoDB supports text search for various languages. text indexes drop
language-specific stop words (e.g. in English, “the”, “an”, “a”,
“and”, etc.) and uses simple language-specific suffix stemming.
The problem with your data is that some of the records have the language-specific stop word, a, which is considered to be a stop word in portugese too. Some of the stop words include, and a is on top of the list.
a
ao
aos
aquela
aquelas
aquele
aqueles
aquilo
as
até
com
como
These words are never indexed, and hence whenever you query for stop words, you get no results.
At the same time, If you query for b, you would get results, since it is not a stop word and would be indexed.

Collectd plugin is reporting an absolute value instead of the delta, for RRD like "Counter" type, to mongo

So I am writing a read plugin, openvz_guest_bandwidth, for Collectd where I read how much bandwidth Openvz guests are doing, by using libiptc to query how much external bandwidth each guest is doing.
I am then reporting this information to the write_mongodb plugin that I wrote, (which could be related to the breakage)
The issue is that I am seeing records in mongo like,
{ "_id" : ObjectId("4f480c15573fa191fa838140"), "ts" : ISODate("2012-02-24T22:15:33Z"), "h" : "62f34634-0fac-4b5f-a7a5-45532ef6dd3b", "i" : "rx", "t" : "counter", "ti" : "", "value" : NumberLong("3970318241") }
{ "_id" : ObjectId("4f480c15573fa191fa838141"), "ts" : ISODate("2012-02-24T22:15:34Z"), "h" : "62f34634-0fac-4b5f-a7a5-45532ef6dd3b", "i" : "tx", "t" : "counter", "ti" : "", "value" : NumberLong(50070094) }
{ "_id" : ObjectId("4f480c15573fa191fa838142"), "ts" : ISODate("2012-02-24T22:15:34Z"), "h" : "62f34634-0fac-4b5f-a7a5-45532ef6dd3b", "i" : "rx", "t" : "counter", "ti" : "", "value" : NumberLong("3970322447") }
{ "_id" : ObjectId("4f480c15573fa191fa838143"), "ts" : ISODate("2012-02-24T22:15:35Z"), "h" : "62f34634-0fac-4b5f-a7a5-45532ef6dd3b", "i" : "tx", "t" : "counter", "ti" : "", "value" : NumberLong(50070094) }
{ "_id" : ObjectId("4f480c15573fa191fa838144"), "ts" : ISODate("2012-02-24T22:15:35Z"), "h" : "62f34634-0fac-4b5f-a7a5-45532ef6dd3b", "i" : "rx", "t" : "counter", "ti" : "", "value" : NumberLong("3970325247") }
Where the interesting values are at the end. I would expect the reported values to be the difference between the consecutive records, instead of what the counter reads.
This is analogous to the RRD counter type of COUNTER instead of ABSOLUTE as I understand it.
I am pretty stuck on this and am unsure where the fault may lie, and even further how to correct it. The fault could either be in reading or with writing.
As a side note, before the values reach write_mongodb, they are sent over the collectd network plugin.
More over I seem to be confused between value_list.plugin and value_list.plugin_instance. Other plugins seem to use types which give a really useless field such as "t: 'memory'" inside the memory collection.
Octo, the collectd maintainer pointed out that the write_mongodb plugin didn't use a certain function call and configuration check to see if it should write deltas.
The commit can be found Here
https://github.com/collectd/collectd/pull/38