How to filter the record in blaze where id is equal to the specified id? - blaze

I am using blaze for querying data from csv and json. I just need to query a record where id is equal to the specified id? Is it possible.
city = city[city.ID = 1]
While trying to execute the above code it shows
SyntaxError: invalid syntax

That works, but in your case you'd need to have a field named ID, it's not a magical field. The following works, but only because there's a column explicitly named id in accounts.csv:
from blaze import Data
from blaze.utils import example
accounts = Data(example('accounts.csv')
accounts[accounts.id == 2]
# id name balance
# 1 2 Bob 200

Related

MS ACCESS table default value code line for autogenerated sequential and unique alphanumeric number

I am new to MS Access and I would like to generate an autogenerated sequential and unique alphanumeric number of the format SYYMM001, SYYMM002, SYYMM003... (ex for 2023 january: S2301001, S2301002, S2301003).
I use MS Access 2016.
I am in my table, in View mode, in the column InvoiceCode in which I want the number to appear, in the general sheet, in Default Value I used the following code:
= "S" & Format(Now(),"yymm") & Format((DCount("[InvoiceID]","InvoiceTable")),"000")
where InvoiceID is the autonumber column and InvoiceTable the name of the table.
This code does not work and generate the following error:
"Unknown function "Dcount" in validation expression or default value on "Invoice Table.InvoiceCode"
I tried another code that I found online which works but instead of giving me a sequential number it generate a random number ex S2301586, S2301236 ...
="S" & Format(Now(),"yymm") & Format(Int(Rnd()*1000),"000")
Would you have a code that would do what I need?
Thanks in advance for your help
You can't set this in the table.
You could try this in your form you use for data entry - in the BeforeInsert event of the form:
Me!InvoiceID.Value = "S" & Format(Date,"yymm") & Format(DCount("*","InvoiceTable"),"000")

How to group records based on a child record in Amazon Quicksight

Is there any way to categorise an aggregated record in Amazon Quicksight based on the records being aggregated?
I'm trying to build a pivot table an Amazon Quicksight to pull out counts of various records split down by what state the record is in limited to a date range where the record first had activity.
This is all being done in SPICE since the raw data is CSV files in S3. The two CSV files are:
Student
Id: String
Current State: One of pass / fail
Department: String
Test
Id: String
Student Id: String
DateOfTest: DateTime
State: One of pass / fail
The pivot table I'm trying to build would have a row for each department and 3 columns:
fail - Count of students in the department where the current state is fail
pass-never-failed - Count of students in the department where the current state is pass and there are no failed tests for the Student
pass-failed-some - Count of students in the department where the current state is pass and there is at least one failed test
To do this I've created a dataset that contains Student joined to Test. I can then create a Pivot table with:
Row: Department
Column: Current State
Value: Count Distinct(Id[Student])
I thought I'd be able to create a calculated field to give me the three categories and use that in place of Current State using the following calculation:
ifelse(
{Current State} = 'pass',
ifelse(
countIf({Id[Test]}, {State} = 'fail') = 0,
'pass-never-failed',
'pass-failed-some'
),
{Current State}
)
But that shows invalid with the following error:
Mismatched aggregation. Custom aggregations can’t contain both aggregate "`COUNT`" and non-aggregated fields “COUNT(CASE WHEN "State" = _UTF16'fail' THEN "Id[Test]" ELSE NULL END)”, in any combination.
Is there any way to categories the Students based on an aggregation of the Tests in quicksight or do I have to pre-calculate this information in the source data?
I've been able to workaround this for now by defining three separate calculations for the three columns and adding these as values in the quicksight pivot rather than setting a column dimension at all.
Count Passed Never Failed
distinct_countIf({Id[Student]}, maxOver(
ifelse({State[Test]} = 'fail' AND {Current State[Student]} = 'pass',
1, 0)
, [{Id[Student]}], PRE_AGG) = 0)
Count Passed Failed Some
distinct_countIf({Id[Student]}, maxOver(
ifelse({State[Test]} = 'fail' AND {Current State[Student]} = 'pass',
1, 0)
, [{Id[Student]}], PRE_AGG) > 0)
Count Failed
distinct_countIf({Id[Student]}, {Current State[Student]} = 'fail')
This works, but I'd still like to know if it's possible to build a dimension that I could use for this as it would be more flexible if new states are added without the special handling of pass.

Xeroizer::ApiException : QueryParseException: No property or field 'inv_id' exists

I am Trying to get all the invoices in a single API hit.
Because, for every user having 100's of invoices.
It will exceed the API limit (Minute Limit: 60 calls in a rolling 60 second window).
I am trying to store all the invoice id into a single array and from that i will get the details of the user and then i loop the records locally and display it. It's the right way?
invoice_ids = user.estimates.select("invoice_id") || [] xero = Xeroizer::PrivateApplication.new(XERO_CONFIG["key"], XERO_CONFIG["secret"], XERO_CONFIG["path"], :rate_limit_sleep => 5)
invoices = ['795f789b-5958-xxxx-yyyy-48436dbe7757','987g389b-5958-xxxx-yyyy-68636dbe5589']
inv_id = invoice_ids.pluck(:invoice_id)
invoices = xero.Invoice.all(:where => 'InvoiceID==inv_id')
Also, I am getting the following error:
Xeroizer::ApiException (QueryParseException: No property or field 'inv_id' exists in type 'Invoice')
Looks like the problem is that you're not interpolating the inv_ids correctly. You probably need to do something like this:
invoices = xero.Invoice.all(:where => "InvoiceID==\"#{inv_id}\"")
You may have to perform some additional formatting on the inv_id variable to make it a valid Xero string. https://github.com/waynerobinson/xeroizer#retrieving-data

Pig: Aggregate with specific parameter dynamically

I have data some data that I want to plot, but the aggregation parameter is dependent on the user. The data looks like this-
Date Country Browser Count
---- ------- ------- -----
2015-07-11,US,Chrome,18
2015-07-11,US,Opera Mini,10
2015-07-11,US,Firefox,21
2015-07-11,US,IE,11
2015-07-11,US,Safari,8
...
2015-07-11,UK,Chrome,102
2015-07-11,UK,IE,45
2015-07-11,UK,Mobile Safari,47
2015-07-11,UK,Firefox,40
...
2015-07-11,DE,Android browser,50
2015-07-11,DE,Chrome,3
2015-07-11,DE,IE,11
2015-07-11,DE,Firefox,20
The user will tell me what to aggregate by (country or browser), and I want to display the counts. For example, grouped by country (aggregated by browser) it would be -
2015-07-11,US,ALL,68
2015-07-11,UK,ALL,234
2015-07-11,DE,ALL,84
whereas grouped by browser (aggregated by country) might be -
2015-07-11,ALL,IE,67
2015-07-11,ALL,Chrome,123
2015-07-11,ALL,Firefox,81
Would I have to write separate scripts based on each column or are there more efficient ways of doing this?
Better to write a macro to which the the alias name and the field name : 'country', 'browser' is passed. Aggregation logic remains the same.
Ref : http://pig.apache.org/docs/r0.10.0/cont.html#macros
Example :
Pig script :
DEFINE AGGR_DATA(alias, field_name) RETURN aggr_alias {
alias_grp = GROUP $alias BY $field_name;
-- REST OF LOGIC
$aggr_alias = -- AGGR DATA;
}
Usage :
aggr_data = AGGR_DATA(browser_data_alias,'country');
Pass the required field name to macro.

Ruby csv file related operations

I'm working on a file related task..I have a CSV file with some rows and headers..I need to fetch column with particular header and create a new column at the end and do some operations..how can i fetch column values which is having particular header value and how can i create new column in the end?
Assuming you have CSV in following format
Zipcode Network ID Network Name Zone New Network? Display Name
64024 275 Kansas City 2 No Kansas City
64034 275 Kansas City 2 No Kansas City
You can user FasterCSV;
If you have headers in your csv then you can specify it headers => true what you can do is to fetch data from row by row using FasterCSV,as given below
FasterCSV.foreach(path_to_file, { :headers => true, :row_sep => :auto }) do |row|
Each time you iterate the csv you would get row from your CSV file, now you already know that column 2 has "network_id" header and column 3 has "network name" header so you can easily give network_id = row[2], network_name = row[3]
hope it would answer your question
First record in CSV may be considered as Header record. There is no rule which dictates that this has to be the case.
Coming to your question. Short answer is that you have to write the logic (using API or without it) to fetch what you consider a "header".
I need to fetch column with particular header and create a new column at the end and do some operations
I don't think API would provide any implicit mechanism to fetch a particular header. AFAIK CSV does not have a spec. You could use FasterCSV like API to parse through the CSV to get the work done.

Resources