Ankiconnect will not add note - anki

I am trying to use Ankconnect to add a note, the deck and the model exists and the fields are correct, but I just get "null" back (and the card is not added).
Running this bash script
echo "---------- The deck exists:"
curl localhost:8765 -X POST -d '{
"action": "getDeckConfig",
"version": 6,
"params": {
"deck": "Foo"
}
}'
echo "---------- The model exists:"
curl localhost:8765 -X POST -d '{
"action": "modelFieldNames",
"version": 6,
"params": {
"modelName": "Auto-generated"
}
}'
echo "---------- But adding a card fails:"
curl localhost:8765 -X POST -d '{
"action": "addNotes",
"version": 6,
"params": {
"notes": {
"deckName": "Foo",
"modelName": "Auto-generated",
"fields": {
"Question": "why?",
"Answer": "because!",
"Card ID": "foo"
},
"options": {
"allowDuplicate": true
},
}
}
}'
Produces these results
---------- The deck exists:
{"result": {"dyn": false, "usn": 82, "timer": 0, "replayq": true, "name": "Default", "id": 1, "lapse": {"mult": 0.0, "minInt": 1, "delays": [10], "leechAction": 0, "leechFails": 8}, "autoplay": true, "rev": {"hardFactor": 1.2, "ivlFct": 1.0, "ease4": 1.3, "perDay": 200, "fuzz": 0.05, "minSpace": 1, "bury": false, "maxIvl": 36500}, "mod": 1560476298, "maxTaken": 60, "new": {"ints": [1, 4, 7], "perDay": 20, "delays": [1, 10], "order": 1, "initialFactor": 2500, "bury": false, "separate": true, "LBGIMinBefore": 1, "LBGIMinAfter": 1, "LBEIMinBefore": 4, "LBEIMinAfter": 4}}, "error": null}
---------- The model exists:
{"result": ["Question", "Answer", "Card ID"], "error": null}
---------- But adding a card fails:
null

There's a few errors in your JSON.
Add "tags": [] to each of your notes objects, as it seems to be mandatory from the tests I've done but can be empty.
This will at least get you an output of {"result": [null, null, null, null, null], "error": null}
But then you need to fix some of your fields
"addNotes" takes an array of "notes" objects, but you're assigning a single object to "notes" and not an array.
"modelName" cannot be "Auto-generated" change it to "Basic"
"Question" should be "Front"
"Answer" should be "Back"
So this is what the object in your curl call should look like:
{
"action": "addNotes",
"version": 6,
"params": {
"notes": [
{
"deckName": "Foo",
"modelName": "Basic",
"fields": {
"Front": "why?",
"Back": "because!",
"Card ID": "foo"
},
"options": {
"allowDuplicate": true
},
"tags": []
}
]
}
}

Related

Grouping sequelize data in separate objects

i am new with nodejs express with posgresql , i made a route like this :
get: async (req, res, next) => {
var cat = await sequelize.query(
`
SELECT
o."id" as "cart_id",
o."user_id",
o."createdBy",
o."createdAt",
o."updatedAt",
i."quantity",
pi."name",
pi."price"
FROM "Orders" AS o
Left join public."CartItem" i on i."cart_id"=o."id"
Left join public."Item" pi on pi."id"=i."product_id"
WHERE o."user_id"=${req.body.user_id}
`
,
{ type: QueryTypes.SELECT,group:`i."cart_id"` })
.catch(e => res.send(e))
if (cat) {
// console.log(cat.Orders)
cat.map(e=> {
console.log(e)
})
res.send(cat)
}
},
if i hit this route with postman i get this response :
[
{
"cart_id": 9,
"user_id": 1,
"createdBy": null,
"createdAt": "2022-11-11T09:51:47.968Z",
"updatedAt": "2022-11-11T09:51:47.968Z",
"quantity": 4,
"name": "test1",
"price": 12000
},
{
"cart_id": 9,
"user_id": 1,
"createdBy": null,
"createdAt": "2022-11-11T09:51:47.968Z",
"updatedAt": "2022-11-11T09:51:47.968Z",
"quantity": 4,
"name": "test2",
"price": 12000
}
]
My question is, is it possible to assemble the response in the following way:
[
"cart_9":[
{
"user_id": 1,
"createdBy": null,
"createdAt": "2022-11-11T09:51:47.968Z",
"updatedAt": "2022-11-11T09:51:47.968Z",
"quantity": 4,
"name": "test1",
"price": 12000
},
{
"user_id": 1,
"createdBy": null,
"createdAt": "2022-11-11T09:51:47.968Z",
"updatedAt": "2022-11-11T09:51:47.968Z",
"quantity": 4,
"name": "test2",
"price": 12000
}
]
]
note that the response assembled by the "cart_id" .
any suggestion to assemble the response and get the required response ?

Terraform AWS Dashboard - Widgets from nested list

Terraform beginner here. I am trying to create some widgets from a nested list. Group will be a "label" widget indicating the group followed by the metric widgets for the canaries related to the group. So the dashboard should look as follows:
Group 1
widget1, widget2 etc.
Group 2
widget3, widget4 etc.
Variable value:
dashboard = [
{
name = "Group-1",
canaries = ["canary1", "canary2", "canary3"]
},
{
name = "Group-2",
canaries = ["canary4", "canary5"]
}
]
Attempt at building json:
locals {
body = [for group in var.dashboard :
#Create text widget for Group name
{
"height": 1,
"width": 24,
"y": 4,
"x": 0,
"type": "text",
"properties": {
"markdown": "\n# > [${group.name}]\n"
}
}
#Attempt to create underlying widgets for group
[for canary in group.canaries :
{
{
"height": 3,
"width": 6,
"y": 5,
"x": 0,
"type": "metric",
"properties": {
"metrics": [
[ "CloudWatchSynthetics", "Failed", "CanaryName", "${canary}", { "label": "Canary failures count", "region": "us-west-2" } ]
],
"title": "Failed canary runs",
"period": 60,
"region": "us-west-2",
"stat": "Sum",
"view": "singleValue",
"setPeriodToTimeRange": true
}
}
}
] #TF Doesn't like the inclusion of nested loop here or my syntax is incorrect.
]
}
Resource creation:
resource "aws_cloudwatch_dashboard" "canary_dashboard" {
dashboard_name = "Canary-Dashboard"
dashboard_body = jsonencode({
"widgets": concat(local.body)
})
}
In my creation of body, Terraform complains about Missing close bracket on index, but I have triple checked that I am not missing a bracket or curly brace. How do I dynamically create the dashboard widgets from nested lists?
Edit
Including desired json output below as suggested by Jordan. In the end, there will be n number of groups, each having n number of canaries belonging to said group.
{
"widgets": [
{
"height": 1,
"width": 24,
"y": 4,
"x": 0,
"type": "text",
"properties": {
"markdown": "\n# Group1\n"
}
},
{
"height": 3,
"width": 6,
"y": 5,
"x": 6,
"type": "metric",
"properties": {
"metrics": [
[ "CloudWatchSynthetics", "Failed", "CanaryName", "Group1-Canary", { "label": "Canary failures count", "region": "us-west-2" } ]
],
"title": "Failed canary runs",
"period": 60,
"region": "us-west-2",
"stat": "Sum",
"view": "singleValue",
"setPeriodToTimeRange": true
}
},
{
"height": 1,
"width": 24,
"y": 4,
"x": 0,
"type": "text",
"properties": {
"markdown": "\n# Group2\n"
}
},
{
"height": 3,
"width": 6,
"y": 5,
"x": 6,
"type": "metric",
"properties": {
"metrics": [
[ "CloudWatchSynthetics", "Failed", "CanaryName", "Group2-Canary", { "label": "Canary failures count", "region": "us-west-2" } ]
],
"title": "Failed canary runs",
"period": 60,
"region": "us-west-2",
"stat": "Sum",
"view": "singleValue",
"setPeriodToTimeRange": true
}
},
]
}
You're trying to do something with list comprehension that Terraform doesn't allow (see where I've marked "HERE"):
locals {
body = [for group in var.dashboard :
#Create text widget for Group name
{
"height": 1,
"width": 24,
"y": 4,
"x": 0,
"type": "text",
"properties": {
"markdown": "\n# > [${group.name}]\n"
}
} <===== HERE
#Attempt to create underlying widgets for group
[for canary in group.canaries :
{
{
"height": 3,
"width": 6,
"y": 5,
"x": 0,
"type": "metric",
"properties": {
"metrics": [
[ "CloudWatchSynthetics", "Failed", "CanaryName", "${canary}", { "label": "Canary failures count", "region": "us-west-2" } ]
],
"title": "Failed canary runs",
"period": 60,
"region": "us-west-2",
"stat": "Sum",
"view": "singleValue",
"setPeriodToTimeRange": true
}
}
}
] #TF Doesn't like the inclusion of nested loop here or my syntax is incorrect.
]
}
If TF allowed you to do what you're trying to do, you'd end up with something like:
body = [
{
"height": 1,
"width": 24,
"y": 4,
"x": 0,
"type": "text",
"properties": {
"markdown": "\n# > [${group.name}]\n"
}
},
[
{
{
"height": 3,
"width": 6,
"y": 5,
"x": 0,
"type": "metric",
"properties": {
"metrics": [
[ "CloudWatchSynthetics", "Failed", "CanaryName", "${canary}", { "label": "Canary failures count", "region": "us-west-2" } ]
],
"title": "Failed canary runs",
"period": 60,
"region": "us-west-2",
"stat": "Sum",
"view": "singleValue",
"setPeriodToTimeRange": true
}
}
},
{
{
"height": 3,
"width": 6,
"y": 5,
"x": 0,
"type": "metric",
"properties": {
"metrics": [
[ "CloudWatchSynthetics", "Failed", "CanaryName", "${canary}", { "label": "Canary failures count", "region": "us-west-2" } ]
],
"title": "Failed canary runs",
"period": 60,
"region": "us-west-2",
"stat": "Sum",
"view": "singleValue",
"setPeriodToTimeRange": true
}
}
}
]
]
And I doubt that's what you're trying to do. If you can provide a sample of what you'd like the JSON to look like, we can show you how to achieve it.

Apollo query has the wrong data from cache

Apollo query has the wrong data from cache in my react app.
If I set query's fetchPolicy to 'network-only', everything work properly.
So I think it is a cache problem.
I have been working hard trying to solve the problem and see articles about apollo cache, but I still can't solve the problem.
Here are my results after querying:
parameter memberId is null (result is correct)
[
{
"id": 87,
"totalQuantity": 12,
"Orders": [
{
"id": 1,
"quantity": 11,
"Member": {
"id": 1,
"name": "A"
}
},
{
"id": 28,
"quantity": 1,
"Member": {
"id": 9,
"name": "B"
}
}
]
},
{
"id": 88,
"totalQuantity": 1,
"Orders": [
{
"id": 2,
"quantity": 1,
"Member": {
"id": 1,
"name": "A"
}
}
]
}
]
parameter memberId is 9 (result is correct)
[
{
"id": 87,
"totalQuantity": 1,
"Orders": [
{
"id": 28,
"quantity": 1,
"Member": {
"id": 9,
"name": "B"
}
}
]
}
]
parameter memberId is 1 (result is correct)
[
{
"id": 87,
"totalQuantity": 11,
"Orders": [
{
"id": 1,
"quantity": 11,
"Member": {
"id": 1,
"name": "A"
}
}
]
},
{
"id": 88,
"totalQuantity": 1,
"Orders": [
{
"id": 2,
"quantity": 1,
"Member": {
"id": 1,
"name": "A"
}
}
]
}
]
but when I back to parameter is null the result is wrong
[
{
"id": 87,
"totalQuantity": 11,
"Orders": [
{
"id": 1,
"quantity": 11,
"Member": {
"id": 1,
"name": "A"
}
}
]
},
{
"id": 88,
"totalQuantity": 1,
"Orders": [
{
"id": 2,
"quantity": 1,
"Member": {
"id": 1,
"name": "A"
}
}
]
}
]
Member B (id = 9) is disappear..
and I back to parameter is 9 (result is wrong)
[
{
"id": 87,
"totalQuantity": 11,
"Orders": [
{
"id": 1,
"quantity": 11,
"Member": {
"id": 1,
"name": "A"
}
}
]
}
]
I get the Member A's data instead of Member B
Can someone help me? Thanks
My client configuration (cache is InMemoryCache)
const client = new ApolloClient({
link: ApolloLink.from([
httpLink,
]),
cache,
dataIdFromObject: o => ${o.id}${o.__typename},
});
I use queryHook to wrap my component
const queryHook = graphql(FETCH_ORDER_GROUP_SHIPMENT_LIST, {
options: ownProps => ({
variables: {
memberId: ownProps.options.memberId || null,
},
}),
props: ({
data: {
orderGroupShipmentList,
},
}) => ({
orderGroupShipmentList: orderGroupShipmentList || [],
});
Also I use Query tag(other data) to wrap my content
and its parameter is memberId as well.
the structure like this
<Query
variables={{ memberId: options.memberId || null }}
query={FETCH_MEMBER_LIST_QUERY}>
content that use orderGroupShipmentList and memberList
</Query>
I don't know if this is specific enough
Let me know if this is not specific enough
Thanks
2019-09-16
For those who facing the same problem:
https://kamranicus.com/posts/2018-03-06-graphql-apollo-object-caching
You need to have different ids for that type on the returned results for your query. For example, you have different results for id 87 based on memberId, so the cache will be overwritten by your second query and since apollo does not refetch queries already made by default it will continue to look at the overwritten result.
#Anymore - can we see you FETCH_MEMBER_LIST_QUERY code? Are you fetching id's for all the data? Without the ids it won't be able to match relations.
Have you tried using Apollo Client DevTools - they will let you easily view the contents of the cache. It can be found on GitHub here and the Chrome Webstore here
Using this you will be able to see if the item is being cached correctly.

Issues in response return by OLA API of cabs availability and estimation in sandbox environment

I am trying to integrate Ola api of cabs availability and estimation in sandbox environment.As per ola documentation, they have created virtual cabs for sandbox environment in KR Puram, Bengaluru, India (Lat: 13.0040167, Lng: 77.6877765) and
Orion Mall, Bengaluru, India (Lat: 13.0107881, Lng: 77.5527122).but when I fired the request with their request url and other header data
(x-app-token,authorization), it doesn't return available cabs data in response.I am using postman for this purpose.Please revert with some solution.
request URL
http://sandbox-t.olacabs.com//v1/products?pickup_lat=13.0040167&pickup_lng=77.6877765&drop_lat=13.0107881&drop_lng=77.5527122&service_type=&category=micro
Response return
{
"categories": [
{
"id": "micro",
"display_name": "Micro",
"currency": "INR",
"distance_unit": "kilometer",
"time_unit": "minute",
"eta": -1,
"distance": -1,
"ride_later_enabled": "true",
"ride_later_allowed": true,
"ride_now_allowed": false,
"image": "http://d1foexe15giopy.cloudfront.net/micro.png",
"cancellation_policy": {
"cancellation_charge": 25,
"currency": "INR",
"cancellation_charge_applies_after_time": 5,
"time_unit": "minute"
},
"fare_breakup": [
{
"type": "flat_rate",
"minimum_distance": 2,
"minimum_time": 1,
"base_fare": "60.0",
"minimum_fare": "0.0",
"cost_per_distance": "9.0",
"waiting_cost_per_minute": 0,
"ride_cost_per_minute": "1.5",
"surcharge": [],
"rates_lower_than_usual": false,
"rates_higher_than_usual": true
},
{
"type": "flat_rate",
"minimum_distance": 0,
"minimum_time": 0,
"base_fare": "90.0",
"minimum_fare": "225.0",
"cost_per_distance": "9.0",
"waiting_cost_per_minute": 0,
"ride_cost_per_minute": "1.5",
"surcharge": [],
"rates_lower_than_usual": false,
"rates_higher_than_usual": true
},
{
"type": "flat_rate",
"minimum_distance": 0,
"minimum_time": 0,
"base_fare": "90.0",
"minimum_fare": "225.0",
"cost_per_distance": "10.5",
"waiting_cost_per_minute": 0,
"ride_cost_per_minute": "1.5",
"surcharge": [],
"rates_lower_than_usual": false,
"rates_higher_than_usual": true
},
{
"type": "flat_rate",
"minimum_distance": 0,
"minimum_time": 0,
"base_fare": "90.0",
"minimum_fare": "225.0",
"cost_per_distance": "9.0",
"waiting_cost_per_minute": 0,
"ride_cost_per_minute": "3.0",
"surcharge": [],
"rates_lower_than_usual": false,
"rates_higher_than_usual": true
}
]
}
],
"ride_estimate": [
{
"category": "micro",
"distance": 21.94,
"travel_time_in_minutes": 50,
"amount_min": 323,
"amount_max": 340,
"discounts": {
"discount_type": "discount",
"discount_code": "RANDOM",
"discount_mode": "AUTO",
"discount": 5,
"cashback": 0
}
}
],
"previous_cancellation_charges": []
}
Expected response should contain cab availability data as follows:(refer from ola documentation)
"all_cabs": [{ // Current locations of nearby cabs
"lat": 12.9543501,
"lng": 77.5438193,
"id":"e0e7ba15f7249207c1d77ec07c1c06",
"bearing":534,
"accuracy":15
},
{
"lat": 12.9561008,
"lng": 77.5464725,
"id":"15f7249207c1d77e9207c1c0601d6c9c",
"bearing":135,
"accuracy":10
}]
}],

Update Elasticsearch Doc field with Array Type

I have a document in the form of:
curl -XPOST localhost:9200/books/book/1 -d '{
"user_id": 1,
"pages": [ {"page_id": 1, "count": 1}, {"page_id": 2, "count": 3}]
}
Now lets say the user reads page 1 again, so I want to increment the count. The document should become:
{
"user_id": 1,
"pages": [ {"page_id": 1, "count": 2}, {"page_id": 2, "count": 3}]
}
But how do you do this update of an element of a list using an if variable?
An example of a simple update in Elasticsearch is as follows:
curl -XPOST localhost:9200/books/book/2 -d '{
"user_id": 1,
"pages": {
"page_1": 1,
"page_2": 2
}
}'
curl -XPOST localhost:9200/books/book/2/_update -d '
{
"script": "ctx._source.pages.page_1+=1"
}'
The document now becomes:
{
"user_id": 1,
"pages": {
"page_1": 1,
"page_2": 2
}
However this more simple format of a doc looses stating the page_id as a field, so the id itself acts as the field. Similarly the value associated to the field has no real definition. Thus this isn't a great solution.
Anyway, would be great to have any ideas on how to update the array accordingly or any ideas on structuring of the data.
Note: Using ES 1.4.4, You also need to add script.disable_dynamic: false to your elasticsearch.yml file.
Assuming I'm understanding your problem correctly, I would probably use a parent/child relationship.
To test it, I set up an index with a "user" parent and "page" child, as follows:
PUT /test_index
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"user": {
"_id": {
"path": "user_id"
},
"properties": {
"user_id": {
"type": "integer"
}
}
},
"page": {
"_parent": {
"type": "user"
},
"_id": {
"path": "page_id"
},
"properties": {
"page_id": {
"type": "integer"
},
"count": {
"type": "integer"
}
}
}
}
}
(I used the "path" parameter in the "_id"s because it makes the indexing less redundant; the ES docs say that path is deprecated in ES 1.5, but they don't say what it's being replaced with.)
Then indexed a few docs:
POST /test_index/_bulk
{"index":{"_type":"user"}}
{"user_id":1}
{"index":{"_type":"page","_parent":1}}
{"page_id":1,"count":1}
{"index":{"_type":"page","_parent":1}}
{"page_id":2,"count":1}
Now I can use a scripted partial update to increment the "count" field of a page. Because of the parent/child relationship, I have to use the parent parameter to tell ES how to route the request.
POST /test_index/page/2/_update?parent=1
{
"script": "ctx._source.count+=1"
}
Now if I search for that document, I will see that it was updated as expected:
POST /test_index/page/_search
{
"query": {
"term": {
"page_id": {
"value": "2"
}
}
}
}
...
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "page",
"_id": "2",
"_score": 1,
"_source": {
"page_id": 2,
"count": 2
}
}
]
}
}
Here is the code all in one place:
http://sense.qbox.io/gist/9c977f15b514ec251aef8e84e9510d3de43aef8a

Resources