How to replicate multiple columns in an array from Raven DB to Relational Database using SQL Replication? - replication

I am doing work to replicate our Raven DB documents into SQL using Raven's SQL Replication tool and only hit a couple of snags so far. I have now started work on one of our most complicated documents and struggling to find the best way to replicate arrays in the documents that contain multiple columns.
This is how the document I am attempting to replicate looks:
{
"CreatedAt": "2013-03-26T15:58:05.5130458",
"IsMostRecent": true,
"ClientId": "clients/417",
"StatusType": "Live",
"Start": "2013-03-31T00:00:00.0000000",
"End": null,
"EndCharge": null,
"AssessmentDate": null,
"Correspondence": null,
"Service": {
"$type": "xxxx.xxxx.xxxx.xxxx.Personalisation, xxxx.Care.Core",
"IsDirectBilling": false,
"Visits": [
{
"DayOfWeek": "Monday",
"Start": "09:00:00",
"End": "10:15:00",
"AdditionalResources": true,
"SocialWork": {
"Duration": 30,
"BillableTo": "SocialWork",
"VisitTasks": [
"GoingToBed",
"DressingAssistance",
"WashingBathingAssistance",
"AssistWithPersonalGrooming"
]
},
"PrivateWork": {
"Duration": 45,
"BillableTo": "Private",
"VisitTasks": [
"SupportWithRehab",
"FoodPreperation",
"ShoppingErrandRunning",
"NonSpecialisedLaundry",
"CheckVisit",
"MealsAtHomeService",
"Escorting"
]
}
},
{
"DayOfWeek": "Wednesday",
"Start": "09:00:00",
"End": "10:15:00",
"AdditionalResources": true,
"SocialWork": {
"Duration": 30,
"BillableTo": "SocialWork",
"VisitTasks": [
"GoingToBed",
"DressingAssistance",
"WashingBathingAssistance",
"AssistWithPersonalGrooming"
]
},
"PrivateWork": {
"Duration": 45,
"BillableTo": "Private",
"VisitTasks": [
"SupportWithRehab",
"FoodPreperation",
"ShoppingErrandRunning",
"NonSpecialisedLaundry",
"CheckVisit",
"MealsAtHomeService",
"Escorting"
]
}
},
{
"DayOfWeek": "Friday",
"Start": "09:00:00",
"End": "10:15:00",
"AdditionalResources": true,
"SocialWork": {
"Duration": 30,
"BillableTo": "SocialWork",
"VisitTasks": [
"GoingToBed",
"DressingAssistance",
"WashingBathingAssistance",
"AssistWithPersonalGrooming"
]
},
"PrivateWork": {
"Duration": 45,
"BillableTo": "Private",
"VisitTasks": [
"SupportWithRehab",
"FoodPreperation",
"ShoppingErrandRunning",
"NonSpecialisedLaundry",
"CheckVisit",
"MealsAtHomeService",
"Escorting"
]
}
}
],
"_visits": [
{
"DayOfWeek": "Monday",
"Start": "09:00:00",
"End": "10:15:00",
"AdditionalResources": true,
"SocialWork": {
"Duration": 30,
"BillableTo": "SocialWork",
"VisitTasks": [
"GoingToBed",
"DressingAssistance",
"WashingBathingAssistance",
"AssistWithPersonalGrooming"
]
},
"PrivateWork": {
"Duration": 45,
"BillableTo": "Private",
"VisitTasks": [
"SupportWithRehab",
"FoodPreperation",
"ShoppingErrandRunning",
"NonSpecialisedLaundry",
"CheckVisit",
"MealsAtHomeService",
"Escorting"
]
}
},
}
}
This is my replication script so far, currently some columns are being replicated but not all:
replicateToServiceStatusDetails({
ClientId: this.ClientId,
StatusType: this.StatusType,
Start: this.Start,
End: this.End,
EndChargeDate: this.EndChargeDate,
AssessmentDate: this.AssessmentDate
});
for (var i=0; i<this.Service.length; i++)
{
replicateToService(
{
IsDirectBilling: this.IsDirectBilling
});
}
for (var i=0; i<this.Service.Visits.length; i++)
{
replicateToVisits(
{
DayOfWeek: this.Service.Visits.DayOfWeek,
Start: this.Service.Visits.Start,
End: this.Service.Visits.End,
AdditionalResources: this.Service.Visits.AdditionalResources
});
}
for (var i=0; i<this.Service.Visits.SocialWork.length; i++)
{
replicateToSocialWork(
{
Duration: this.Service.Visits.SocialWork.Duration,
BillableTo: this.Service.Visits.SocialWork.BillableTo
});
}
for (var i=0; i<this.Service.Visits.PrivateWork.length; i++)
{
replicateToPrivateWork(
{
Duration: this.Service.Visits.PrivateWork.Duration,
BillableTo: this.Service.Visits.PrivateWork.BillableTo
});
}
Looking for some ideas on how to get all columns replicated.

You only need for if you are iterating over arrays. This is probably how you want to do this:
replicateToServiceStatusDetails({
ClientId: this.ClientId,
StatusType: this.StatusType,
Start: this.Start,
End: this.End,
EndChargeDate: this.EndChargeDate,
AssessmentDate: this.AssessmentDate
});
replicateToService(
{
IsDirectBilling: this.IsDirectBilling
});
for (var i=0; i<this.Service.Visits.length; i++)
{
var visit = this.Service.Visits[i];
replicateToVisits(
{
DayOfWeek: visit.DayOfWeek,
Start: visit.Start,
End: visit.End,
AdditionalResources: visit.AdditionalResources
});
replicateToSocialWork(
{
Duration: visit.SocialWork.Duration,
BillableTo: visit.SocialWork.BillableTo
});
replicateToPrivateWork(
{
Duration: visit.PrivateWork.Duration,
BillableTo: visit.PrivateWork.BillableTo
});
}

Related

Vue3 Chart not updating after sending data into Data series in Apex Chart

When I send data into the apex chart array that I took from my json file with axios, the chart does not automatically renew itself in Vue3
With Axios, I fetch all the apexcharts in the json file and add them to the elementCustomize array. Then I push the data in the elementDataseries array into elementCustomize[i].options.series one by one, the data goes into the series of the related apexchart successfully, but I can't see the change in the chart in the page. I can see the data whenever I write a text in the page and save it.
Can you help me?
That is my json file
"elementCustomize": [
{
"id": "2023024145531",
"customizeId": 0,
"elementId": 2023024145531,
"pageId": 1,
"zone": "zone1",
"options": {
"series": [ {
"elementId" : 2023024145531,
"dataId" : 123453576978982,
"name" : "Data 1",
"data" : [-44,55,187,11,61,22,63,45,3]
}],
"chart": {
"type": "bar",
"height": 280,
"toolbar": {
"show": true,
"tools": {
"download": true,
"selection": true,
"zoom": true,
"zoomin": true,
"zoomout": true,
"pan": true,
"reset": true
}
}
},
"plotOptions": {
"bar": {
"horizontal": false,
"columnWidth": "55%",
"endingShape": "rounded"
}
},
"colors": [
"#0150581244",
"#2196F3",
"#4CAF50",
"#9C27B0"
],
"dataLabels": {
"enabled": false
},
"stroke": {
"show": true,
"width": 2,
"colors": [
"transparent"
]
},
"xaxis": {
"categories": [
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct"
]
},
"yaxis": {
"title": {
"text": "$ (thousands)"
}
},
"fill": {
"opacity": 1
},
"legend": {
"position": "top",
"horizontalAlign": "center"
},
"title": {
"text": "Multiple Bars",
"align": "left"
},
"tooltip": {
"y": {}
}
}
},
{
"id": "2023025111221",
"customizeId": 0,
"elementId": "2023025111221",
"pageId": 1,
"zone": "zone3",
"options": {
"series": [],
"chart": {
"type": "bar",
"height": 280,
"toolbar": {
"show": true,
"tools": {
"download": true,
"selection": true,
"zoom": true,
"zoomin": true,
"zoomout": true,
"pan": true,
"reset": true
}
}
},
"plotOptions": {
"bar": {
"horizontal": false,
"columnWidth": "55%",
"endingShape": "rounded"
}
},
"colors": [
"#0150581244",
"#2196F3",
"#4CAF50",
"#9C27B0"
],
"dataLabels": {
"enabled": false
},
"stroke": {
"show": true,
"width": 2,
"colors": [
"transparent"
]
},
"xaxis": {
"categories": [
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct"
]
},
"yaxis": {
"title": {
"text": "$ (thousands)"
}
},
"fill": {
"opacity": 1
},
"legend": {
"position": "top",
"horizontalAlign": "center"
},
"title": {
"text": "Multiple Bars",
"align": "left"
},
"tooltip": {
"y": {}
}
}
}
]
The process where I pull this data from the json and sync it into the array
onBeforeMount(async () => {
await api.get(jsonServerUrl+"elementCustomize?pageId="+pageID).then(response=>{
elementCustomize = response.data
})
}
That is my apex chart code
<div v-for="item in filteredCustomize('zone1')" :key="item.id" class="drag-item s-card">
<ApexChart
id="apex-chart-1 chart"
:height="item.options.chart.height"
:type="item.options.chart.type"
:series="item.options.series"
:options="item.options"
>
</ApexChart>
{{item.options.series}}
<div class="elementHeadBar hover" align="start">
<VButton icon="feather:edit-2" color="info" :loading="loading" raised #click="updateSeries(item)"> test push series </VButton>
</div>
</div>
filteredCustomize for filtering areas, because i have 3 column in page. zone1, zone2, zone3 etc.
const filteredCustomize=(e)=>{
return elementCustomize.filter(item => item.zone === e)
}
I am posting fake datas with updateseries function.
const updateSeries = (item)=> {
let matchingData = elementDataSeries.filter(e => e.elementId == item.id)
if (matchingData){
for(let i = 0; i < elementCustomize.length; i++) {
for(let j = 0; j < elementDataSeries.length; j++) {
if(elementCustomize[i].elementId === elementDataSeries[j].elementId) {
elementCustomize[i].options.series.push(elementDataSeries[j]);
}
}
}
}else{
console.log("no")
}
console.log(elementCustomize)
}
i tried watch but it doesn't work. i read something in forums. when post data into apexchart series, it have to re render automatically.

MongoDB Lookup values based on dynamic field name

I'm pretty sure the below can be done, I'm struggling to understand how to do it in MongoDB.
My data is structured like this (demo data):
db={
"recipes": [
{
"id": 1,
"name": "flatbread pizza",
"ingredients": {
"1010": 1,
"1020": 2,
"1030": 200
}
},
{
"id": 2,
"name": "cheese sandwich",
"ingredients": {
"1040": 1,
"1050": 2
}
}
],
"ingredients": [
{
"id": 1010,
"name": "flatbread",
"unit": "pieces"
},
{
"id": 1020,
"name": "garlic",
"unit": "clove"
},
{
"id": 1030,
"name": "tomato sauce",
"unit": "ml"
},
{
"id": 1040,
"name": "bread",
"unit": "slices"
},
{
"id": 1050,
"name": "cheese",
"unit": "slices"
}
]
}
The output I'm trying to achieve would look like this:
[
{
"id": 1,
"name": "flatbread pizza",
“flatbread”: “1 pieces”,
“garlic”: “2 cloves”,
“tomato sauce”: “200 ml”
},
{
"id": 2,
"name": "cheese sandwich",
“bread”: “1 slices”,
“cheese”: “2 slices”
}
]
I've tried several approaches, and I get stuck at the bit where I need to do a lookup based on the ingredient name (which actually is the id). I tried using $objectToArray to turn it into a k-v document, but then I get stuck in how to construct the lookup pipeline.
This is not a simple solution, and probably can be improved:
db.recipes.aggregate([
{
"$addFields": {
ingredientsParts: {
"$objectToArray": "$ingredients"
}
}
},
{
$unwind: "$ingredientsParts"
},
{
"$group": {
_id: "$id",
name: {
$first: "$name"
},
ingredientsParts: {
$push: {
v: "$ingredientsParts.v",
id: {
$toInt: "$ingredientsParts.k"
}
}
}
}
},
{
"$lookup": {
"from": "ingredients",
"localField": "ingredientsParts.id",
"foreignField": "id",
"as": "ingredients"
}
},
{
$unwind: "$ingredients"
},
{
"$addFields": {
"ingredientsPart": {
"$filter": {
input: "$ingredientsParts",
as: "item",
cond: {
$eq: [
"$$item.id",
"$ingredients.id"
]
}
}
}
}
},
{
$project: {
ingredients: 1,
ingredientsPart: {
"$arrayElemAt": [
"$ingredientsPart",
0
]
},
name: 1
}
},
{
"$addFields": {
units: {
k: "$ingredients.name",
v: {
"$concat": [
{
$toString: "$ingredientsPart.v"
},
" ",
"$ingredients.unit"
]
}
}
}
},
{
$group: {
_id: "$_id",
name: {
$first: "$name"
},
units: {
$push: "$units"
}
}
},
{
"$addFields": {
"data": {
"$arrayToObject": "$units"
}
}
},
{
"$addFields": {
"data.id": "$_id",
"data.name": "$name"
}
},
{
"$replaceRoot": {
"newRoot": "$data"
}
}
])
You can see it works here
As rickhg12hs said, it can be modeled better.

GA4 data api - (not set) in custom dimensions

We are currently using GA4 data API and faced the issue when custom dimensions returns value "(not set)".
We were using the following article to set custom dimension for the session count, but we still receiving "(not set)" values.
Example of request:
{
"dateRanges": [
{
"startDate": "2021-09-01",
"endDate": "2021-09-05"
}
],
"offset": 0,
"limit": 100,
"dimensionFilter": {
"filter": {
"fieldName": "eventName",
"stringFilter": {
"matchType": 1,
"value": "screen_view",
"caseSensitive": true
}
}
},
"dimensions": [
{
"name": "customUser:applicationID"
},
{
"name": "customEvent:ga_session_number"
},
{
"name": "dateHour"
},
{
"name": "platform"
},
{
"name": "sessionSource"
},
{
"name": "sessionMedium"
},
{
"name": "sessionCampaignName"
},
{
"name": "deviceCategory"
}
],
"metrics": [
{
"name": "userEngagementDuration"
}
]
}
Does anybody have any idea why it may happen?

How to use a nested json-based formation value in the jQuery.dataTables?

Now suppose I have a json data formation like this following:
{
"ServiceName": "cacheWebApi",
"Description": "This is a CacheWebApiService",
"IsActive": true,
"Urls": [{ "ServiceAddress": "http://192.168.111.210:8200", "Weight": 5, "IsAvailable": true },
{ "ServiceAddress": ",http://192.168.111.210:8200", "Weight": 3, "IsAvailable": true }]
}
Now what worries me is that the "Urls" is another nested json formation. So how to bind this value to the datatables? And have you got any good ideas (e.g:something like I only wanna show all the ServiceAddress)...
This should do what you need:
var data = [{
"ServiceName": "cacheWebApi",
"Description": "This is a CacheWebApiService",
"IsActive": true,
"Urls": [
{
"ServiceAddress": "http://192.168.111.210:8200",
"Weight": 5,
"IsAvailable": true
},
{
"ServiceAddress": ",http://192.168.111.210:8200",
"Weight": 3,
"IsAvailable": true
}
]
}];
$(function() {
var table = $('#example').dataTable({
"data": data,
"columns": [
{
"data": "ServiceName"
}, {
"data": "Description"
}, {
"data": "IsActive"
}, {
"data": "Urls[0].ServiceAddress"
}, {
"data": "Urls[0].Weight"
}, {
"data": "Urls[0].IsAvailable"
}, {
"data": "Urls[1].ServiceAddress"
}, {
"data": "Urls[1].Weight"
}, {
"data": "Urls[1].IsAvailable"
}
],
});
});
You should put your data in an array though. Working JSFiddle
EDIT
IF the number of Urls isn't defined then you could do something like this:
var table = $('#example').dataTable({
"data": data,
"columns": [
{
"data": "ServiceName"
}, {
"data": "Description"
}, {
"data": "IsActive"
}, {
"data": "Urls",
"render": function(d){
return JSON.stringify(d);
}
}
],
});
I guess that that isn't brilliant but you could do almost anything to that function, for instance:
var table = $('#example').dataTable({
"data": data,
"columns": [
{
"data": "ServiceName"
}, {
"data": "Description"
}, {
"data": "IsActive"
}, {
"data": "Urls",
"render": function(d){
return d.map(function(c){
return c.ServiceAddress
}).join(", ");
}
}
],
});

ElasticSearch combine match and function score queries

I have a complicated query to run in elasticsearch that spans across multiple fields (nested and non-nested). I am using a bool should query across a multi-field match and nested field match.
Additionally I want a composite scoring which takes into account several other parameters such as location, rating etc.
I tried to run a simplified proof of concept combined query which looks for a matching term and tries to use function score for the other fields but I am running into an error from es.
GET init/restaurant/_search/
{
"query": {
"match": {
"cuisine_categories": "Oriental"
},
"function_score": {
"functions": [
{
"gauss": {
"coordinates": {
"origin": { "lat": 74.20, "lon": 31.23 },
"offset": "1km",
"scale": "3km"
}
}
},
{
"gauss": {
"nomnom_rating": {
"origin": "4.5",
"offset": "0.5",
"scale": "1"
}
},
"weight": 2
},
{
"gauss": {
"estimated_preparation_time": {
"origin": "30",
"offset": "10",
"scale": "20"
}
},
"weight": 5
}
]
}
}
}
The query is not a valid. The match clause should be within the query object of function score as shown below
Example:
POST init/restaurant/_search/
{
"query": {
"function_score": {
"functions": [
{
"gauss": {
"coordinates": {
"origin": {
"lat": 74.2,
"lon": 31.23
},
"offset": "1km",
"scale": "3km"
}
}
},
{
"gauss": {
"nomnom_rating": {
"origin": "4.5",
"offset": "0.5",
"scale": "1"
}
},
"weight": 2
},
{
"gauss": {
"estimated_preparation_time": {
"origin": "30",
"offset": "10",
"scale": "20"
}
},
"weight": 5
}
],
"query": {
"match": {
"cuisine_categories": "Oriental"
}
}
}
}
}