Missing } after property list, can't find it - mongodb-query

I don't fully understand jquery yet but I am in the middle of a course to learn some.
Part of my course required me to enter:
db.grades.aggregate(
{'$group':{'_id':'$student_id', 'average':{'$avg':'$score'}}},
{'$sort':{'average':-1}},
{'$limit':1}
)
It is throwing this error:
[thread1] SyntaxError: missing } after property list #(shell)1:39
I can't see the missing }, can someone please help me?

You should use array
db.grades.aggregate([
{'$group':{'_id':'$student_id', 'average':{'$avg':'$score'}}},
{'$sort':{'average':-1}},
{'$limit':1}
])

Aggregate pipes must be in an array, check the docs here: https://docs.mongodb.com/v3.2/reference/method/db.collection.aggregate/
db.grades.aggregate([
{'$group':{'_id':'$student_id', 'average':{'$avg':'$score'}}},
{'$sort':{'average':-1}},
{'$limit':1}
])

Related

Cab Dafny use an imported ADT in a match command

Hi I am running into time out problems and am trying to decompose my file into different modules on the hope that a verified module will not have to be reverified, in VS code, when working on a module that imports it.
If any one knows if this is a reasonable way to avoid time out problems I would like to hear.
But the more basic problem I found is that once I import an ADT I can make use of in in if statements but not in match statements. See code below for an example. Any ideas on what I am doing wrong?
module inner {
datatype Twee = Node(value : int, left : Twee, right : Twee) | Leaf
function rot(t:Twee) :Twee
{
match t
case Leaf => t
case Node(v,l,r) => Node(v,r,l)
}
}
module outer {
import TL = inner
function workingIf(t:TL.Twee) :TL.Twee
{ if (t == TL.Leaf) then TL.Leaf else t }
function failingMatch(t:TL.Twee) :TL.Twee
{
match t
case TL.Leaf => t // error "darrow expected"
case TL.Node(v,l,r) => TL.Node(v,r,l)
}
}
Sorry for asking the question - the following worked.
function failingMatch(t:TL.Twee) :TL.Twee
{
match t
case Leaf => t
case Node(v,l,r) => TL.Node(v,r,l)
}
Well that worked but the following failed
function rotateLeft(t:TL.Twee) :TL.Twee
{
match t
case Leaf => t
case Node(v,Leaf,r) => TL.Node(v,TL.Leaf,r)
case Node(v,Node(vl,ll,rl),r) => TL.Node(vl,ll,TL.Node(v,rl,r))
}
The answer to the first question was given by James Wilcox and can be found in What are the relationships among imports, includes, and verification in Dafny?
but for convienience I repeat below:
"import has no direct influence on whether the imported module is verified or not. Modules in other files will not be verified unless their file is listed on the command line. Modules in the current file are always verified (whether or not they are imported by anyone)."
The main question I have raised in https://github.com/dafny-lang/dafny/issues/870
Many thanks to everyone - teaching how to use Dafny with out stack overflow would be so much harder.
Somewhat oddly, the constructor names that follow each case keyword are expected to be unqualified. They are looked up in the type of the expression that follows the match. It's quirky that qualified names are not allowed, and this is likely something that will be corrected in the future (I thought there was a Dafny issue on github about this, but I can't find it).

How can i get the result of an query from BigQuery in Airflow, and attach it into an email auto-send to me

I want to use dynamic time {{ macros.ds_add(ds, 0) }}, so pandas_gbq.read_gbq doesn't work.
I also used the get_pandas_df of BigQueryHook, it showed 'BigQueryPandasConnector' object has no attribute 'http_error', the document says that I need to override DbApiHook method, but I don't know how.
And is there any solution for this issue? Appreciate for your help, guys.
Use BigQueryGetDataOperator. Following is an example:
Example: ::
get_data = BigQueryGetDataOperator(
task_id='get_data_from_bq',
dataset_id='test_dataset',
table_id='Transaction_partitions',
max_results='100',
selected_fields='DATE',
bigquery_conn_id='airflow-service-account'
)
Official Documentation: https://airflow.readthedocs.io/en/stable/integration.html#bigquerygetdataoperator

[odoo10]How to save the record while odoo warning is happend?

In my custom module I added the
application_no = fields.Char(string="Application Number")
_sql_constraints = [
('application_no_unique',
'UNIQUE(application_no)',
"Application Number already exist.Please specify another number or make sure the application number is correct"),
]
and I use sql constraint to shows warning.
It works correctly, When we entered duplicate application number it shows the warning and access to saving the record is prevented
Question
How to save the record while warning happens??
note
I think SQL constraint is not suited for this.
is any other method for this functionality?
I think it might help you to use an onchange method :
#api.onchange('your_field')
def your_onchange(self):
count=self.search_count([('your_field','=',self.your_field)])
return {
'warning': {'title': _('Warning'), 'message': _('Warning message'),},
}
This will show you the message and you can save without problems. I hope this help you.

Why am I getting “Too many positionals passed…” in this call to HTTP::Request.new?

I tried six or so variations on this code and excepting hardcoded Strs like GET => … I always got this error. Why? How can I fix it and understand it? Is it a bug in the HTTP::Request code?
Code
#!/usr/bin/env perl6
use HTTP::UserAgent; # Installed today with panda, for HTTP::Request.
HTTP::Request.new( GET => "/this/is/fine" ).WHICH.say;
# First, check that yes, they are there.
say %*ENV<REQUEST_METHOD>, " ", %*ENV<REQUEST_URI>;
# This and single value or slice combination always errors-
HTTP::Request.new( %*ENV<REQUEST_METHOD>, %*ENV<REQUEST_URI> );
Output with invariable error
$ env REQUEST_METHOD=GET REQUEST_URI=/ SOQ.p6
HTTP::Request|140331166709152
GET /
Too many positionals passed; expected 1 argument but got 3
in method new at lib/HTTP/Request.pm6:13
in block <unit> at ./SOQ.p6:11
HTTP::Request is from this package — https://github.com/sergot/http-useragent/ — Thank you!
Try
HTTP::Request.new(|{ %*ENV<REQUEST_METHOD> => %*ENV<REQUEST_URI> });
instead of the more obvious
HTTP::Request.new( %*ENV<REQUEST_METHOD> => %*ENV<REQUEST_URI> );
If the left-hand side of => isn't a literal, we won't bind to a named parameter. Instead, a pair object gets passed as positional argument.
To work around this, we construct an anonymous hash that gets flattened into the argument list via prefix |.
As a bonus, here are some more creative ways to do it:
HTTP::Request.new(|%( %*ENV<REQUEST_METHOD REQUEST_URI> ));
HTTP::Request.new(|[=>] %*ENV<REQUEST_METHOD REQUEST_URI> );

Mule ESB: How to do Condition checking in Datamapper using Xpath

i'm facing issue in xpath-I need do a check two attribute values, if the condition satisfies need to do hard code my own value. Below is my xml.
I need to check the condition like inside subroot- if ItemType=Table1 and ItemCondition=Chair1 then i have to give a hard coded value 'Proceed'( this hard coded value i will map to target side of datamapper).
<Root>
<SubRoot>
<ItemType>Table1</ItemType>
<ItemCondition>Chair1</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
<SubRoot>
<ItemType>Table2</ItemType>
<ItemCondition>chair2</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
....Will have multiple subroot
</Root>
I have tried to define rules as below, but it is throwing error
Type: String
Context:/Root
Xpath: substring("Proceed", 1 div boolean(/SubRoot[ItemType="Table1" and ItemCondition="Chair1"]))
But it is throwing error like
net.sf.saxon.trans.XPathException: Arithmetic operator is not defined for arguments of types (xs:integer, xs:boolean)
Is there any other shortcut way to perform this.Could you please help me, i have given lot more effort. Not able to resolve it. Thanks in advance.
I am not sure where you are applying this but the XPath expression you are looking for is:
fn:contains(/Root/SubRoot[2]/ItemCondition, "chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")
So here is an example returning "Proceed" or "Stop" as appropriate:
if (fn:contains(/Root/SubRoot[1]/ItemCondition, "Chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")) then 'Proceed' else 'Stop'
To implement the above condition , i was initially tired to do in xpath, gave me lot of error. I have implemented by simple if else condition in script part of data mapper
if ( (input.ItemType == 'Table') and (input.ItemCondition == 'chair')) {
output.Item = 'Proceed'}
else {
output.Item = 'Stop '};
Make sure about your precedence. Example, Here in the xml structure( or converted POJO) ItemType has to be checked first then followed with ItemCondition.
&& not seems to be working for me, change to 'and' operator
If you were first time trying to implement the logic. It may help you.