How to give a date of start for users on Freeradius - mysql

I want to be able to delay the activation of the login. For example i can create an user monday, but i just want allow him to connect only from friday to logon on my network.
So i created an attribute on the file dictionary.conf
ATTRIBUTE Acc-start-date 3003 date
This attribute is used in the databse sql like an attribute
And in the /site-available/default in the authorise section
if (Acc-Start-Date < "%{Current-Time}") {
reject
}
But I get an error,
rad_recv: Access-Request packet from host 127.0.0.1 port 58341, id=131, length=277
ChilliSpot-Version = "1.3.0"
User-Name = "date"
User-Password = "date"
Service-Type = Login-User
Acct-Session-Id = "556ea52d00000004"
Framed-IP-Address = 10.10.4.200
NAS-Port-Type = Wireless-802.11
NAS-Port = 4
NAS-Port-Id = "00000004"
Calling-Station-Id = "00-1B-77-16-34-1A"
Called-Station-Id = "00-50-56-B2-BF-8D"
NAS-IP-Address = 10.10.4.254
NAS-Identifier = "vlan4"
WISPr-Location-ID = "isocc=,cc=,ac=,network=Coova,Vlan4_ssid"
WISPr-Location-Name = "Vlan_4"
WISPr-Logoff-URL = "http://10.10.4.254:3990/logoff"
Message-Authenticator = 0x96a538a9ed829e695c3d62f22e5d1962
Wed Jun 3 08:57:48 2015 : Info: # Executing section authorize from file /etc/freeradius/sites-enabled/default
Wed Jun 3 08:57:48 2015 : Info: +- entering group authorize {...}
Wed Jun 3 08:57:48 2015 : Info: ++? if (!NAS-IP-Address)
Wed Jun 3 08:57:48 2015 : Info: ? Evaluating !(NAS-IP-Address) -> FALSE
Wed Jun 3 08:57:48 2015 : Info: ++? if (!NAS-IP-Address) -> FALSE
Wed Jun 3 08:57:48 2015 : Info: ++[preprocess] returns ok
Wed Jun 3 08:57:48 2015 : Info: ++[chap] returns noop
Wed Jun 3 08:57:48 2015 : Info: ++[mschap] returns noop
Wed Jun 3 08:57:48 2015 : Info: ++[digest] returns noop
Wed Jun 3 08:57:48 2015 : Info: [suffix] No '#' in User-Name = "date", looking up realm NULL
Wed Jun 3 08:57:48 2015 : Info: [suffix] No such realm "NULL"
Wed Jun 3 08:57:48 2015 : Info: ++[suffix] returns noop
Wed Jun 3 08:57:48 2015 : Info: [eap] No EAP-Message, not doing EAP
Wed Jun 3 08:57:48 2015 : Info: ++[eap] returns noop
Wed Jun 3 08:57:48 2015 : Info: [sql] expand: %{User-Name} -> date
Wed Jun 3 08:57:48 2015 : Info: [sql] sql_set_user escaped user --> 'date'
Wed Jun 3 08:57:48 2015 : Debug: rlm_sql (sql): Reserving sql socket id: 3
Wed Jun 3 08:57:48 2015 : Info: [sql] expand: SELECT id, username, attribute, value, op FROM radcheck WHERE username = '%{SQL-User-Name}' ORDER BY id -> SELECT id, username, attribute, value, op FROM radcheck WHERE username = 'date' ORDER BY id
Wed Jun 3 08:57:48 2015 : Info: [sql] User found in radcheck table
Wed Jun 3 08:57:48 2015 : Info: [sql] expand: SELECT id, username, attribute, value, op FROM radreply WHERE username = '%{SQL-User-Name}' ORDER BY id -> SELECT id, username, attribute, value, op FROM radreply WHERE username = 'date' ORDER BY id
Wed Jun 3 08:57:48 2015 : Info: [sql] expand: SELECT groupname FROM usergroup WHERE username = '%{SQL-User-Name}' ORDER BY priority -> SELECT groupname FROM usergroup WHERE username = 'date' ORDER BY priority
Wed Jun 3 08:57:48 2015 : Info: [sql] expand: SELECT id, groupname, attribute, Value, op FROM radgroupcheck WHERE groupname = '%{Sql-Group}' ORDER BY id -> SELECT id, groupname, attribute, Value, op FROM radgroupcheck WHERE groupname = 'date_check' ORDER BY id
Wed Jun 3 08:57:48 2015 : Info: [sql] User found in group date_check
Wed Jun 3 08:57:48 2015 : Info: [sql] expand: SELECT id, groupname, attribute, value, op FROM radgroupreply WHERE groupname = '%{Sql-Group}' ORDER BY id -> SELECT id, groupname, attribute, value, op FROM radgroupreply WHERE groupname = 'date_check' ORDER BY id
Wed Jun 3 08:57:48 2015 : Debug: rlm_sql (sql): Released sql socket id: 3
Wed Jun 3 08:57:48 2015 : Info: ++[sql] returns ok
Wed Jun 3 08:57:48 2015 : Debug: rlm_sqlcounter: Entering module authorize code
Wed Jun 3 08:57:48 2015 : Debug: rlm_sqlcounter: Could not find Check item value pair
Wed Jun 3 08:57:48 2015 : Info: ++[chillispot_max_bytes] returns noop
Wed Jun 3 08:57:48 2015 : Debug: rlm_sqlcounter: Entering module authorize code
Wed Jun 3 08:57:48 2015 : Debug: rlm_sqlcounter: Could not find Check item value pair
Wed Jun 3 08:57:48 2015 : Info: ++[noresetcounter] returns noop
Wed Jun 3 08:57:48 2015 : Debug: rlm_sqlcounter: Entering module authorize code
Wed Jun 3 08:57:48 2015 : Debug: rlm_sqlcounter: Could not find Check item value pair
Wed Jun 3 08:57:48 2015 : Info: ++[dailycounter] returns noop
Wed Jun 3 08:57:48 2015 : Info: ++? if (Acc-Start-Date < "%{Current-Time}")
Wed Jun 3 08:57:48 2015 : Info: expand: %{Current-Time} ->
Wed Jun 3 08:57:48 2015 : Info: (Attribute Acc-Start-Date was not found)
Wed Jun 3 08:57:48 2015 : Info: ? Evaluating (Acc-Start-Date < "%{Current-Time}") -> FALSE
Wed Jun 3 08:57:48 2015 : Info: ++? if (Acc-Start-Date < "%{Current-Time}") -> FALSE
Wed Jun 3 08:57:48 2015 : Info: ++[expiration] returns noop
Wed Jun 3 08:57:48 2015 : Info: ++[logintime] returns noop
Wed Jun 3 08:57:48 2015 : Info: ++[pap] returns updated
My freeradius can't find my attribut, should I write somewhere the query sql to find this attribute ?

You might want to add this in your policy.conf and not default
if (Acc-start-date < "%{Current-Time}") {
reject
}

Related

Finding the error in the script that runs a FIFO/LIFO calculation on a transactional history of an investment tracker

Introduction
I have a spreadsheet and the idea of this spreadsheet is that any user can input his or her transaction history in the sheet "history" and based on this history, an overview is provided of a person's realized gains (=they have sold it in the past) and their unrealized gains (= never sold it). A script is run which then creates a report (sheet: Report) with the necessary data. A query table summarises this data in the summary of RG report sheet. Based on this summary, the position sheet is created, which shows all the current positions held by the user. The user can chose to run the script by going to the menu CoinAtlas>Build Report>LIFO or HIFO. Please see here the sample sheet.
What is FIFO and LIFO?
These are accepted accounting methods to calculate realized gains. FIFO (=first in, first out) & LIFO (=last in, first out). An example of FIFO: You buy 2 stocks of company A for 10 dollars each at date Y. At date Y+1 you buy 2 more stocks of company A for 15 dollars each. You hold 4 stocks of company A. You decide to sell 3 stocks of company A for 20 dollars each. Profit is then calculated as (3 * 20-(2 * 10+1 * 15)) = 60 - 35 = 25 dollars. The same scenario LIFO would be: 60 - 40 = 20 dollars.
Description of the problem
When building a report, for whatever reason, the stock MSTR and the cryptocurrency THETA is ignored and not shown in the output sheet "Report". The script was written by an experienced programmer who unfortunately no longer responds to this issue. With my beginner's skills in javascript I cannot seem to find out why.
The FIFO script calculation
function createReport_LIFO () {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const inputSheet = ss.getSheetByName('History');
const report = ss.getSheetByName('Report');
const data = inputSheet.getRange(2, 1, inputSheet.getLastRow() - 1, 9).getValues();
const filterd = data.filter(row => row[2] == 'Buy' || row[2] == 'Sell');
const sorted = filterd.sort((a, b) => {
if (a[0] < b[0]) return 1
if (a[0] > b[0]) return -1
else return 0
})
//console.log(sorted);
const securityObject = sorted.reduce((acc, curr) => {
if (curr[1] in acc) {
if (curr[2] in acc[curr[1]]) {
acc[curr[1]][curr[2]].push(curr)
} else {
acc[curr[1]] = { ...acc[curr[1]], [curr[2]]: [curr] }
}
} else {
acc[curr[1]] = { [curr[2]]: [curr] }
}
return acc
}, {});
console.log(JSON.stringify(securityObject));
//console.log(securityObject);
const objects = [];
Object.keys(securityObject).forEach(ticker => {
const tic = securityObject[ticker];
let index = 0;
try {
tic.Sell.forEach(sell => {
const [date, security, , quanity, total, , account, ] = sell;
let totalBuy = 0;
let remainder = quanity;
do {
let [, , , buyQuanity, , buyPrice] = tic.Buy[index];
if (buyQuanity < remainder) {
totalBuy += (buyQuanity * buyPrice);
remainder -= buyQuanity;
index++;
} else {
totalBuy += (remainder * buyPrice);
securityObject[ticker].Buy[index][3] = (buyQuanity - remainder);
buyQuanity -= remainder;
remainder = 0;
if (buyQuanity <= 0) {
index++;
}
}
} while (remainder > 0);
objects.push({
date,
security,
account,
quanity,
totalBuy,
total,
result: total - totalBuy
})
})
} catch (err) {
console.log(err)
}
})
const convertToSheetsArray = [["Sell Date", "Security", "Account", "Quantity Sold", "Total Buy", "Total Sell", "Result"]]
objects.forEach(obj => convertToSheetsArray.push(Object.values(obj)));
report.getDataRange().clearContent();
report.getRange(1, 1, convertToSheetsArray.length, 7).setValues(convertToSheetsArray);
}
Output of securityObject
Logging output too large. Truncating output. {"ETH":{"Buy":[["2021-10-26T22:00:00.000Z","ETH","Buy",0.087541,301.25,3441.2446739242187,"Bitvavo","Cryptocurrency",""],["2021-07-11T22:00:00.000Z","ETH","Buy",1.19,2113.84,1776.3361344537818,"Bitvavo","Cryptocurrency",""],["2021-07-09T22:00:00.000Z","ETH","Buy",0.109074,195.55,1792.8195536974897,"Binance","Cryptocurrency",""],["2021-07-09T22:00:00.000Z","ETH","Buy",0.0529245,94.95,1794.0651305161127,"Binance","Cryptocurrency",""],["2021-07-09T22:00:00.000Z","ETH","Buy",0.0443436,81.22,1831.6059138184542,"Binance","Cryptocurrency",""],["2021-07-09T22:00:00.000Z","ETH","Buy",0.31543836,576.66,1828.1226164122843,"Binance","Cryptocurrency",""],["2021-07-05T22:00:00.000Z","ETH","Buy",0.19039196,498.75,2619.595911508028,"Bitvavo","Cryptocurrency",""],["2021-07-05T22:00:00.000Z","ETH","Buy",0.57131,1116.81,1954.823125798603,"Binance","Cryptocurrency",""],["2021-05-18T22:00:00.000Z","ETH","Buy",0.1036,250,2413.127413127413,"Binance","Cryptocurrency",""]]},"MATIC":{"Sell":[["2021-10-21T22:00:00.000Z","MATIC","Sell",37.14,61.82,1.6645126548196014,"Binance","Cryptocurrency",""]],"Buy":[["2021-05-18T22:00:00.000Z","MATIC","Buy",37.14,65,1.7501346257404415,"Binance","Cryptocurrency",""]]},"XTZ":{"Buy":[["2021-10-21T22:00:00.000Z","XTZ","Buy",8.6,58.82,6.839534883720931,"Binance","Cryptocurrency",""],["2021-09-25T22:00:00.000Z","XTZ","Buy",35.17,200,5.686664771111743,"Bitvavo","Cryptocurrency",""],["2021-09-11T22:00:00.000Z","XTZ","Buy",35.777,200,5.590183637532493,"Bitvavo","Cryptocurrency",""]]},"TFUEL":{"Sell":[["2021-10-20T22:00:00.000Z","TFUEL","Sell",754,182,0.2413793103448276,"Binance","Cryptocurrency",""]],"Buy":[["2021-07-04T22:00:00.000Z","TFUEL","Buy",754,261,0.34615384615384615,"Binance","Cryptocurrency",""]]},"THETA":{"Sell":[["2021-10-20T22:00:00.000Z","THETA","Sell",81.4,397.73,4.886117936117936,"Binance","Cryptocurrency",""]],"Buy":[["2021-03-26T23:00:00.000Z","THETA","Buy",19.5,200.56,10.285128205128204,"Binance","Cryptocurrency",""],["2021-03-20T23:00:00.000Z","THETA","Buy",26,200,7.6923076923076925,"Binance","Cryptocurrency",""],["2021-03-19T23:00:00.000Z","THETA","Buy",35.9,249.81,6.95849582172702,"Binance","Cryptocurrency",""]]},"ONE":{"Buy":[["2021-10-20T22:00:00.000Z","ONE","Buy",2768,579.73,0.2094400289017341,"Binance","Cryptocurrency",""],["2021-09-11T22:00:00.000Z","ONE","Buy",1241,200,0.16116035455278002,"Binance","Cryptocurrency",""]]},"ALGO":{"Buy":[["2021-09-25T22:00:00.000Z","ALGO","Buy",145.18,200,1.3776002204160351,"Bitvavo","Cryptocurrency",""]]},"UPST":{"Buy":[["2021-08-09T22:00:00.000Z","UPST","Buy",2.8786672,336,116.7206824046906,"Trading212","Stock",""]]},"AXS":{"Buy":[["2021-08-08T22:00:00.000Z","AXS","Buy",3,106,35.333333333333336,"Binance","Cryptocurrency",""]]},"safemars":{"Sell":[["2021-08-08T22:00:00.000Z","safemars","Sell",206130076,16,7.762089021885385e-8,"Binance","Cryptocurrency",""]],"Buy":[["2021-04-19T22:00:00.000Z","safemars","Buy",206130076,200,9.70261127735673e-7,"Binance","Cryptocurrency",""]]},"safemoon":{"Sell":[["2021-08-08T22:00:00.000Z","safemoon","Sell",55800000,90,0.0000016129032258064516,"Binance","Cryptocurrency",""]],"Buy":[["2021-04-19T22:00:00.000Z","safemoon","Buy",55800000,300,0.000005376344086021505,"Binance","Cryptocurrency",""]]},"FRA:C36":{"Sell":[["2021-07-13T22:00:00.000Z","FRA:C36","Sell",358,343.68,0.96,"Bitvavo","Stock",""]],"Buy":[["2021-03-18T23:00:00.000Z","FRA:C36","Buy",358,253.9,0.7092178770949721,"DeGiro","Stock",""]]},"BTC":{"Sell":[["2021-07-11T22:00:00.000Z","BTC","Sell",0.038237,1116.81,29207.57381593744,"Binance","Cryptocurrency",""],["2021-07-04T22:00:00.000Z","BTC","Sell",0.00537222,257,47838.69610700977,"Binance","Cryptocurrency",""],["2021-07-04T22:00:00.000Z","BTC","Sell",0.00543778,261,47997.528403135104,"Binance","Cryptocurrency",""],["2021-07-04T22:00:00.000Z","BTC","Sell",0.00533832,261,48891.78617992178,"Binance","Cryptocurrency",""],["2021-07-04T22:00:00.000Z","BTC","Sell",0.00550857,261,47380.71768172139,"Binance","Cryptocurrency",""],["2021-07-04T22:00:00.000Z","BTC","Sell",0.00008389000000000313,0,0,"Bitvavo","Cryptocurrency",""],["2021-06-06T22:00:00.000Z","BTC","Sell",0.038276,1116.81,29177.81377364406,"Binance","Cryptocurrency",""],["2021-05-02T22:00:00.000Z","BTC","Sell",0.01032703,498.75,48295.58934175654,"Bitvavo","Cryptocurrency",""],["2021-04-13T22:00:00.000Z","BTC","Sell",0.18413661999999997,9757,52987.83044893515,"Bitvavo","Cryptocurrency",""]],"Buy":[["2021-06-23T22:00:00.000Z","BTC","Buy",0.038276,1000,26126.03197826314,"Binance","Cryptocurrency",""],["2021-04-14T22:00:00.000Z","BTC","Buy",0.18428,9757,52946.60299544172,"Bitvavo","Cryptocurrency",""],["2021-03-22T23:00:00.000Z","BTC","Buy",0.00094112,43.52,46242.77456647399,"Bitvavo","Cryptocurrency",""],["2021-02-21T23:00:00.000Z","BTC","Buy",0.025382,1000,39397.99858167205,"Bitvavo","Cryptocurrency",""],["2021-02-21T23:00:00.000Z","BTC","Buy",0.046151,1770.3,38358.86546337024,"Bitvavo","Cryptocurrency",""],["2021-02-21T23:00:00.000Z","BTC","Buy",0.046339,2003,43224.929325190446,"Bitvavo","Cryptocurrency",""],["2021-02-16T23:00:00.000Z","BTC","Buy",0.048543,2045.36,42135.0143172033,"Bitvavo","Cryptocurrency",""],["2021-02-07T23:00:00.000Z","BTC","Buy",0.0027187,100,36782.28565123036,"Bitvavo","Cryptocurrency",""],["2021-01-23T23:00:00.000Z","BTC","Buy",0.0077802,200,25706.2800442148,"Bitvavo","Cryptocurrency",""],["2021-01-10T23:00:00.000Z","BTC","Buy",0.0019139,50,26124.66691049689,"Bitvavo","Cryptocurrency",""],["2021-01-09T23:00:00.000Z","BTC","Buy",0.0043677,134,30679.7628042219,"Bitvavo","Cryptocurrency",""]]},"BAT":{"Sell":[["2021-07-09T22:00:00.000Z","BAT","Sell",168.5,81.22,0.4820178041543027,"Binance","Cryptocurrency",""]],"Buy":[["2021-05-30T22:00:00.000Z","BAT","Buy",168.5,100,0.5934718100890207,"Binance","Cryptocurrency",""]]},"BNB":{"Sell":[["2021-07-09T22:00:00.000Z","BNB","Sell",0.7359,195.55,265.7290392716402,"Binance","Cryptocurrency",""]],"Buy":[["2021-05-18T22:00:00.000Z","BNB","Buy",0.7359,250,339.7200706617747,"Binance","Cryptocurrency",""]]},"LINK":{"Sell":[["2021-07-09T22:00:00.000Z","LINK","Sell",6.2,94.95,15.314516129032258,"Binance","Cryptocurrency",""]],"Buy":[["2021-07-04T22:00:00.000Z","LINK","Buy",6.2,261,42.096774193548384,"Binance","Cryptocurrency",""]]},"XMR":{"Sell":[["2021-07-09T22:00:00.000Z","XMR","Sell",3.09982,681,219.69017555858085,"Binance","Cryptocurrency",""]],"Buy":[["2021-05-24T22:00:00.000Z","XMR","Buy",1.51782,300,197.65189548167768,"Binance","Cryptocurrency",""],["2021-05-18T22:00:00.000Z","XMR","Buy",1.192,250,209.73154362416108,"Binance","Cryptocurrency",""],["2021-04-19T22:00:00.000Z","XMR","Buy",0.39,100,256.4102564102564,"Binance","Cryptocurrency",""]]},"RUNE":{"Buy":[["2021-07-04T22:00:00.000Z","RUNE","Buy",17.2,261,15.174418604651164,"Binance","Cryptocurrency",""]]},"SOL":{"Buy":[["2021-07-04T22:00:00.000Z","SOL","Buy",7.0007542,257,36.71033043839762,"Binance","Cryptocurrency",""]]},"KSM":{"Buy":[["2021-05-30T22:00:00.000Z","KSM","Buy",0.3869,100,258.46471956577926,"Binance","Cryptocurrency",""]]},"ADA":{"Buy":[["2021-05-18T22:00:00.000Z","ADA","Buy",164.44,250,1.5203113597664801,"Binance","Cryptocurrency",""],["2021-03-19T23:00:00.000Z","ADA","Buy",236,249.5,1.0572033898305084,"Binance","Cryptocurrency",""]]},"TSLA":{"Sell":[["2021-05-16T22:00:00.000Z","TSLA","Sell",1.8606349999999998,864,464.357598346801,"Trading212","Stock",""],["2021-01-18T23:00:00.000Z","TSLA","Sell",0.1449193,100.45,693.144391395763,"Trading212","Stock",""]],"Buy":[["2021-03-04T23:00:00.000Z","TSLA","Buy",0.3166797,150,473.6647154838153,"Trading212","Stock",""],["2021-03-02T23:00:00.000Z","TSLA","Buy",0.3841205,213.44,555.6589663920566,"Trading212","Stock",""],["2021-02-24T23:00:00.000Z","TSLA","Buy",0.3282356,188.45,574.1302893409489,"Trading212","Stock",""],["2021-02-22T23:00:00.000Z","TSLA","Buy",0.2252006,126.5,561.7214163727805,"Trading212","Stock",""],["2021-02-21T23:00:00.000Z","TSLA","Buy",0.2954647,184.99,626.0984814768059,"Trading212","Stock",""],["2021-02-21T23:00:00.000Z","TSLA","Buy",0.1624873,100,615.4327138182492,"Trading212","Stock",""],["2021-01-10T23:00:00.000Z","TSLA","Buy",0.1449193,100,690.03]
Produced errors
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
10:25:02 AM Info [TypeError: Cannot read property 'forEach' of undefined]
I am hoping someone here can help me solve this issue.
EDIT1: Adding the console.log output of tic.Sell
2:02:36 PM Info undefined
2:02:36 PM Info [ [ Thu Oct 21 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'MATIC',
'Sell',
37.14,
61.82,
1.6645126548196014,
'Binance',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info undefined
2:02:36 PM Info [ [ Wed Oct 20 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'TFUEL',
'Sell',
754,
182,
0.2413793103448276,
'Binance',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info [ [ Wed Oct 20 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'THETA',
'Sell',
81.4,
397.73,
4.886117936117936,
'Binance',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info undefined
2:02:36 PM Info undefined
2:02:36 PM Info undefined
2:02:36 PM Info undefined
2:02:36 PM Info [ [ Sun Aug 08 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'safemars',
'Sell',
206130076,
16,
7.762089021885385e-8,
'Binance',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info [ [ Sun Aug 08 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'safemoon',
'Sell',
55800000,
90,
0.0000016129032258064516,
'Binance',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info [ [ Tue Jul 13 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'FRA:C36',
'Sell',
358,
343.68,
0.96,
'Bitvavo',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Jul 11 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BTC',
'Sell',
0.038237,
1116.81,
29207.57381593744,
'Binance',
'Cryptocurrency',
'' ],
[ Sun Jul 04 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BTC',
'Sell',
0.00537222,
257,
47838.69610700977,
'Binance',
'Cryptocurrency',
'' ],
[ Sun Jul 04 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BTC',
'Sell',
0.00543778,
261,
47997.528403135104,
'Binance',
'Cryptocurrency',
'' ],
[ Sun Jul 04 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BTC',
'Sell',
0.00533832,
261,
48891.78617992178,
'Binance',
'Cryptocurrency',
'' ],
[ Sun Jul 04 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BTC',
'Sell',
0.00550857,
261,
47380.71768172139,
'Binance',
'Cryptocurrency',
'' ],
[ Sun Jul 04 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BTC',
'Sell',
0.00008389000000000313,
0,
0,
'Bitvavo',
'Cryptocurrency',
'' ],
[ Sun Jun 06 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BTC',
'Sell',
0.038276,
1116.81,
29177.81377364406,
'Binance',
'Cryptocurrency',
'' ],
[ Sun May 02 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BTC',
'Sell',
0.01032703,
498.75,
48295.58934175654,
'Bitvavo',
'Cryptocurrency',
'' ],
[ Tue Apr 13 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BTC',
'Sell',
0.18413661999999997,
9757,
52987.83044893515,
'Bitvavo',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info [ [ Fri Jul 09 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BAT',
'Sell',
168.5,
81.22,
0.4820178041543027,
'Binance',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info [ [ Fri Jul 09 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'BNB',
'Sell',
0.7359,
195.55,
265.7290392716402,
'Binance',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info [ [ Fri Jul 09 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'LINK',
'Sell',
6.2,
94.95,
15.314516129032258,
'Binance',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info [ [ Fri Jul 09 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'XMR',
'Sell',
3.09982,
681,
219.69017555858085,
'Binance',
'Cryptocurrency',
'' ] ]
2:02:36 PM Info undefined
2:02:36 PM Info undefined
2:02:36 PM Info undefined
2:02:36 PM Info undefined
2:02:36 PM Info [ [ Sun May 16 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'TSLA',
'Sell',
1.8606349999999998,
864,
464.357598346801,
'Trading212',
'Stock',
'' ],
[ Mon Jan 18 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'TSLA',
'Sell',
0.1449193,
100.45,
693.144391395763,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Mon Apr 12 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'MSTR',
'Sell',
0.61234957,
413.5,
675.2678866092778,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info undefined
2:02:36 PM Info [ [ Sun Apr 11 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'ACTC',
'Sell',
8,
109.91,
13.73875,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Apr 11 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'CTRM',
'Sell',
110,
43.46,
0.3950909090909091,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Apr 11 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'NVCN',
'Sell',
74,
61.85,
0.8358108108108109,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Apr 11 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'SFT',
'Sell',
13,
92.2,
7.092307692307693,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info undefined
2:02:36 PM Info [ [ Sun Apr 11 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'SNGX',
'Sell',
65,
80.2,
1.2338461538461538,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Mar 28 2021 18:00:00 GMT-0400 (Eastern Daylight Time),
'LMND',
'Sell',
1.6704908,
121.86,
72.94862084843568,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info undefined
2:02:36 PM Info [ [ Thu Mar 25 2021 19:00:00 GMT-0400 (Eastern Daylight Time),
'AZRX',
'Sell',
100,
112.35,
1.1235,
'Trading212',
'Stock',
'' ],
[ Thu Mar 25 2021 19:00:00 GMT-0400 (Eastern Daylight Time),
'AZRX',
'Sell',
59,
66.14,
1.1210169491525424,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info undefined
2:02:36 PM Info [ [ Thu Mar 18 2021 19:00:00 GMT-0400 (Eastern Daylight Time),
'FB',
'Sell',
1,
244.81,
244.81,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Mon Mar 15 2021 19:00:00 GMT-0400 (Eastern Daylight Time),
'ARB',
'Sell',
173.1368712,
482.54,
2.7870435491616994,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Wed Mar 10 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'GNUS',
'Sell',
72,
134.94,
1.8741666666666665,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Mon Mar 08 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'ABNB',
'Sell',
0.4281417,
66.98,
156.44353259680148,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Mon Mar 08 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'EQQQ',
'Sell',
1,
253.87,
253.87,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info undefined
2:02:36 PM Info undefined
2:02:36 PM Info [ [ Mon Mar 08 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'QDVA',
'Sell',
6,
48.93,
8.155,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Mon Mar 08 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'SPY',
'Sell',
5,
273.66,
54.732000000000006,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Mon Mar 08 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'SXLV',
'Sell',
7,
188.23,
26.889999999999997,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Mar 07 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'BABA',
'Sell',
1.7718482,
342.51,
193.3066275090609,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Mar 07 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'NIO',
'Sell',
1.888702,
61.79,
32.71558986012616,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Wed Feb 24 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'IQQH',
'Sell',
5,
60.09,
12.018,
'DeGiro',
'Stock',
'' ],
[ Wed Feb 24 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'IQQH',
'Sell',
2,
25.63,
12.815,
'DeGiro',
'Stock',
'' ],
[ Wed Feb 24 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'IQQH',
'Sell',
8,
102.46,
12.8075,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Mon Feb 22 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'ESPO',
'Sell',
5,
191.18,
38.236000000000004,
'Trading212',
'Stock',
'' ],
[ Mon Feb 22 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'ESPO',
'Sell',
4.994859,
186.59,
37.35640986061869,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Feb 21 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'AMZN',
'Sell',
0.05568394,
147.39,
2646.903218414501,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Feb 21 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'COUP',
'Sell',
0.5194278,
155.58,
299.521896979715,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Feb 21 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'CRWD',
'Sell',
0.5152084,
99.28,
192.69872152705585,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Feb 21 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'FVRR',
'Sell',
0.5002109,
122.67,
245.2365592193213,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Feb 21 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'TTWO',
'Sell',
1,
160.04,
160.04,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Wed Jan 27 2021 18:00:00 GMT-0500 (Eastern Standard Time),
'NAKD',
'Sell',
55.421,
68.03,
1.2275130365745837,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Mon Dec 07 2020 18:00:00 GMT-0500 (Eastern Standard Time),
'OTGLY',
'Sell',
6.180493,
91.07,
14.735070487095445,
'Trading212',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Sun Nov 29 2020 18:00:00 GMT-0500 (Eastern Standard Time),
'WDI',
'Sell',
23,
8.21,
0.35695652173913045,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Tue Sep 08 2020 18:00:00 GMT-0400 (Eastern Daylight Time),
'ADP',
'Sell',
1,
114.63,
114.63,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Tue Sep 08 2020 18:00:00 GMT-0400 (Eastern Daylight Time),
'AQN',
'Sell',
3,
35.2,
11.733333333333334,
'DeGiro',
'Stock',
'' ] ]
2:02:36 PM Info [ [ Tue Sep 08 2020 18:00:00 GMT-0400 (Eastern Daylight Time),
'MGRC',
'Sell',
1,
53.1,
53.1,
'DeGiro',
'Stock',
'' ] ]
The problem exists inside the do/while loop.
Remainder becomes incredibly small (for MSTR, remainder = 5.551115123125783e-17 instead of 0) but not quite zero, so the loop runs again and an error is thrown. MSTR and THETA are thus never pushed into objects.
Fixed the issue by changing while (remainder > 1e-9). Might not be the best fix but it works.

Ansible converting month to integer

I haven't found anything for this yet.
I am using Ansible and I'm trying to change some values after a decent amount of time.
But my problem is I get a value like:
2020 Nov 19
But I need it to be like:
2020 11 19
How can I do this?
using to_datetime and strftime you can achieve it. the filters to apply would be:
"{{ '%Y %m %d' | strftime(( my_date_string | to_datetime('%Y %b %d')).strftime('%s')) }}"
as reference, please see the examples here. The idea is to convert your string value to datetime using the to_datetime, then to epoch time using strftime, and finally reformat that to your desired YYYY MM DD.
A PB with 3 example dates:
---
- hosts: localhost
gather_facts: false
vars:
my_date_examples:
- "2020 Nov 04"
- "2020 Apr 11"
- "2020 Aug 23"
tasks:
- name: reformat date string
debug:
msg: "{{ '%Y %m %d' | strftime(( item | to_datetime('%Y %b %d')).strftime('%s')) }}"
loop: "{{ my_date_examples }}"
output:
TASK [reformat date string] *******************************************************************************************************************************************************************************************
ok: [localhost] => (item=2020 Nov 04) => {
"msg": "2020 11 04"
}
ok: [localhost] => (item=2020 Apr 11) => {
"msg": "2020 04 11"
}
ok: [localhost] => (item=2020 Aug 23) => {
"msg": "2020 08 23"
}
cheers

Convert numerical month to string using ionic 2 Pipe

How can I convert month to string in ionic 2 using Pipe? given the sample data below:
In my .ts file
let users = [
{
user: "A",
birthDate: "2017-08-01"
},
{
user: "B",
birthDate: "2017-08-02"
},
{
user: "C",
birthDate: "2017-08-03"
},
{
user: "D",
birthDate: "2017-08-04"
}
]
In my .html file
<ion-list>
<ion-item *ngFor="let user of users">
<div>Name: {{user.name}}</div>
<div>Birth Date: {{user.birthDate | date: "MM dd, yyyy"}}</div>
</ion-item>
</ion-list>
The sample output will be
Name: A
Birth Date: 08 01, 2017
Name: B
Birth Date: 08 02, 2017
Name: C
Birth Date: 08 03, 2017
Name: D
Birth Date: 08 04, 2017
Expected output will be
Name: A
Birth Date: August 01, 2017
Name: B
Birth Date: August 02, 2017
Name: C
Birth Date: August 03, 2017
Name: D
Birth Date: August 04, 2017
How can I achieve expected output?
Use MMMM instead of MM
<ion-list>
<ion-item *ngFor="let user of users">
<div>Name: {{user.name}}</div>
<div>Birth Date: {{user.birthDate | date: "MMMM dd, yyyy"}}</div>
</ion-item>
</ion-list>

Selecting all the records from table to which given number belongs to

Suppose I have following three records in my model :
#<Rda:0xf6e8a0c
id: 1,
age_group: "18-100",
weight: "60",
nutrient: "energy(kcal/day)",
value: "2730",
created_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00,
updated_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00>
#<Rda:0xf6e8a0c
id: 2,
age_group: "10-15",
weight: "60",
nutrient: "energy(kcal/day)",
value: "2730",
created_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00,
updated_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00>
#<Rda:0xf6e8a0c
id: 3,
age_group: "20-100",
weight: "60",
nutrient: "energy(kcal/day)",
value: "2730",
created_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00,
updated_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00>
Now, I want to get all those records in which my given value falls in a 'age_group' columns ranges. For example: suppose my age is 25 then I should get records with ids 1 & 3 from the above records because '25' falls in between '18-100' and '20-100'
You might do
def self.foo(age)
all.select { |rda| Range.new(*rda.age_group.split('-').map(&:to_i)).cover? age }
end

update_attributes failing when I try to update an attribute

I have a user database as User(id: integer, username: string, created_at: datetime, updated_at: datetime, password_digest: string, admin: boolean, usermanager: boolean).
I want to update an user and make him Admin, setting the admin varaible to true.
My update in the controller:
def update
#user = User.find(params[:id])
if #user.update_attributes(user_params)
flash[:success] = "User edited"
redirect_to current_user
else
render users_url
end
end
The update_attributes is failing in all cases. I opened a debugger and tried to call update_attributes, it is failing there as well.
(byebug) user_params = {"admin"=>true}
{"admin"=>true}
(byebug) #user
#<User id: 1, username: "dsmegha", created_at: "2015-09-11 07:42:01", updated_at: "2015-09-13 03:25:01", password_digest: "$2a$10$BInH6J1dXHanqNIdGag6megSyrmm95AmjTEGPemNdGU...", admin: false, usermanager: nil>
(byebug) #user.update_attributes(user_params)
(0.2ms) begin transaction
User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE ("users"."username" = 'dsmegha' AND "users"."id" != 1) LIMIT 1
(0.2ms) rollback transaction
false
The update_attribute works for the same.
(byebug) #user.update_attribute(:admin,true)
(0.2ms) begin transaction
(0.1ms) commit transaction
true
(byebug) #user
#<User id: 1, username: "dsmegha", created_at: "2015-09-11 07:42:01", updated_at: "2015-09-13 03:25:01", password_digest: "$2a$10$BInH6J1dXHanqNIdGag6megSyrmm95AmjTEGPemNdGU...", admin: true, usermanager: nil>
(byebug)
Any idea what I am missing here?
Maybe I think current user data is invalid. please check user.errors.
example)
user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,:confirmable,
:recoverable, :rememberable, :trackable, :validatable, :lockable
validates :name, presence: true
end
pry
pry(main)> user = User.last
=> #<User:0x007fe328fe56d8
id: 3,
email: "hogehoge#example.com",
name: "",
encrypted_password: "$2a$10$I.xXo0AtAz8nuCUzOGclPe6PA//XMZtjW6fh94D1t25jb7eV9bsS.",
current_sign_in_at: Tue, 02 Jun 2015 01:53:08 JST +09:00,
last_sign_in_at: Tue, 02 Jun 2015 01:52:20 JST +09:00,
current_sign_in_ip: "127.0.0.1",
last_sign_in_ip: "127.0.0.1",
created_at: Tue, 02 Jun 2015 01:49:40 JST +09:00,
updated_at: Sun, 13 Sep 2015 13:16:26 JST +09:00,
confirmation_token: nil,
confirmed_at: Tue, 02 Jun 2015 01:52:01 JST +09:00,
confirmation_sent_at: Tue, 02 Jun 2015 01:49:40 JST +09:00,
unconfirmed_email: nil,
failed_attempts: 0,
unlock_token: nil,
locked_at: nil,
status: 1>
[7] pry(main)> user.update_attributes(status: 2)
(0.1ms)
BEGIN
(0.2ms)
ROLLBACK
=> false
[8] pry(main)> user.errors
=> #<ActiveModel::Errors:0x007fe328d893f8
#base=
#<User:0x007fe328fe56d8
id: 3,
email: "hogehoge#example.com",
name: "",
encrypted_password: "$2a$10$I.xXo0AtAz8nuCUzOGclPe6PA//XMZtjW6fh94D1t25jb7eV9bsS.",
reset_password_token: "XWmjsEBujb2-aWd5YHYT",
reset_password_sent_at: nil,
remember_created_at: nil,
sign_in_count: 2,
current_sign_in_at: Tue, 02 Jun 2015 01:53:08 JST +09:00,
last_sign_in_at: Tue, 02 Jun 2015 01:52:20 JST +09:00,
current_sign_in_ip: "127.0.0.1",
last_sign_in_ip: "127.0.0.1",
created_at: Tue, 02 Jun 2015 01:49:40 JST +09:00,
updated_at: Sun, 13 Sep 2015 13:16:26 JST +09:00,
confirmation_token: nil,
confirmed_at: Tue, 02 Jun 2015 01:52:01 JST +09:00,
confirmation_sent_at: Tue, 02 Jun 2015 01:49:40 JST +09:00,
unconfirmed_email: nil,
failed_attempts: 0,
unlock_token: nil,
locked_at: nil,
status: 2>,
#messages={:name=>["can't be blank"]}>
additionally write.
View has password input field perhaps? In that case, I think you need to delete passward params when update user data.
How about this?
user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,:confirmable,
:recoverable, :rememberable, :trackable, :validatable, :lockable
validates :name, presence: true
def update_without_current_password(params, *options)
params.delete(:current_password)
if params[:password].blank?
params.delete(:password)
params.delete(:password_confirmation) if params[:password_confirmation].blank?
end
clean_up_passwords
update_attributes(params, *options)
end
end
controller
def update
#user = User.find(params[:id])
if #user.update_without_current_password(user_params)
flash[:success] = "User edited"
redirect_to current_user
else
render users_url
end
end