How to select a single row, where multiple rows match join criteria? - azure-data-explorer

In the table, EVENTDATA (see below), I would like to select a single row per day for each user.
For example:
name
eventDate
eventName
User1
2022-1-21
car
User1
2022-1-21
bus
User1
2022-1-23
bus
User1
2022-1-23
horse
The result set should only include a single row for each day.
name
eventDate
eventName
User1
2022-1-21
bus
User1
2022-1-23
bus
// Test query
// EVENTDATA: This table holds the name of the event in addtion to the user name and date. We only need one row for each unique date for each user.
let EVENTDATA = datatable(name:string, eventDate:datetime, eventName: string)
[
'Jack', datetime(2022-01-12), 'Mets',
'Jack', datetime(2022-01-12), 'Dentist',
'Jack', datetime(2022-01-12), 'Movie',
'Jack', datetime(2022-01-13), 'Mets',
'Jack', datetime(2022-01-13), 'Movie',
'Jack', datetime(2022-01-14), 'Anything',
'Jack', datetime(2022-01-14), 'Else',
'Jack', datetime(2022-01-14), 'Movie',
'Jack', datetime(2022-01-15), 'Mets',
'Jack', datetime(2022-01-15), 'Dentist',
'Jack', datetime(2022-01-15), 'Movie',
'Jill', datetime(2022-01-18), 'Thing1',
'Jill', datetime(2022-01-18), 'Thing2',
'Jill', datetime(2022-01-18), 'Cats',
'Jill', datetime(2022-01-22), 'Play',
'Jill', datetime(2022-01-25), 'Darts',
'Jill', datetime(2022-01-30), 'Make',
'Jill', datetime(2022-01-30), 'Samples',
'Jill', datetime(2022-01-30), 'Shorter',
'Mary', datetime(2022-01-17), 'Cricket',
'Mary', datetime(2022-01-20), 'Football',
'Mary', datetime(2022-01-20), 'Rugby',
'Mary', datetime(2022-01-22), 'Curling'
];

distinct operator
let EVENTDATA = datatable(name:string, eventDate:datetime, eventName: string)
[
'Jack', datetime(2022-01-12), 'Mets',
'Jack', datetime(2022-01-12), 'Dentist',
'Jack', datetime(2022-01-12), 'Movie',
'Jack', datetime(2022-01-13), 'Mets',
'Jack', datetime(2022-01-13), 'Movie',
'Jack', datetime(2022-01-14), 'Anything',
'Jack', datetime(2022-01-14), 'Else',
'Jack', datetime(2022-01-14), 'Movie',
'Jack', datetime(2022-01-15), 'Mets',
'Jack', datetime(2022-01-15), 'Dentist',
'Jack', datetime(2022-01-15), 'Movie',
'Jill', datetime(2022-01-18), 'Thing1',
'Jill', datetime(2022-01-18), 'Thing2',
'Jill', datetime(2022-01-18), 'Cats',
'Jill', datetime(2022-01-22), 'Play',
'Jill', datetime(2022-01-25), 'Darts',
'Jill', datetime(2022-01-30), 'Make',
'Jill', datetime(2022-01-30), 'Samples',
'Jill', datetime(2022-01-30), 'Shorter',
'Mary', datetime(2022-01-17), 'Cricket',
'Mary', datetime(2022-01-20), 'Football',
'Mary', datetime(2022-01-20), 'Rugby',
'Mary', datetime(2022-01-22), 'Curling'
];
EVENTDATA
| distinct name, eventDate
name
eventDate
Jack
2022-01-12T00:00:00Z
Jack
2022-01-13T00:00:00Z
Jack
2022-01-14T00:00:00Z
Jack
2022-01-15T00:00:00Z
Mary
2022-01-17T00:00:00Z
Jill
2022-01-18T00:00:00Z
Mary
2022-01-20T00:00:00Z
Jill
2022-01-22T00:00:00Z
Mary
2022-01-22T00:00:00Z
Jill
2022-01-25T00:00:00Z
Jill
2022-01-30T00:00:00Z
Fiddle

Related

How to parse JSON objects that depend on array contents for their attributes with JQ?

I have this complex array of JSON objects that have attributes that are arrays which may or may not be populated.
I am looking for a way using jq to filter out the array elements that do not have any items in their updates attribute, but this is buried deep down the object tree.
Is there a way to produce the sample output from the input JSON array under it?
What I am trying to find is:
Select all top level objects from the array that have a baseBranch attribute and a non-empty config attribute and filter out the results to show me only the elements within the (gradle and gradle-wrapper) attributes within the config that have a non-empty deps array attribute. The result is a deps element that have a non-empty updates array in it.
Thanks in advance to anyone who can take this challenge!
Edit:
Yes I have tried solving it on my own. I have been through the documentation and so far this is the expression I have: .[] | . as $parent | select(.baseBranch != null and .config != null) | .config | [.gradle[] .deps[]]
This will filter out all the top level elements and get me to the dependency array, but I cannot figure out how to filter out the deps array and group them by the attribute where they are located.
Edit 2:
The query bellow is returning most of the information I want. But I'd like to figure out how to group the updates by the repository and file values.
jq '.[]
| . as $parent
| select(.baseBranch != null and .config != null)
| .config.gradle[]?.deps[]? as $deps
| [
{
repository: $parent.repository,
file:$deps.managerData.packageFile,
depName:$deps.depName,
currentVersion:$deps.currentValue,
newVersion:$deps.updates[]?.newVersion
}
]
'
/* Desired sample output */
[
{
"repository": "repositoryName",
"numberOfUpdates": 5,
"gradleUpdates": [
{
"fileName": "dependencies.gradle",
"package": "packageName.api:feature-flags", /* if packageName then display the depName */
"currentVersion": "0.20.0",
"newVersion": "0.21.0"
},
{
"fileName": "dependencies.gradle",
"package": "io.rest-assured:xml-path", /* if packageName then display the depName */
"currentVersion": "4.5.1",
"newVersion": "5.1.1"
},
{
"fileName": "build.gradle",
"package": "com.diffplug.spotless:com.diffplug.spotless.gradle.plugin", /* if packageName then display the depName */
"currentVersion": "6.9.0",
"newVersion": "6.10.0"
},
{
"fileName": "build.gradle",
"package": "org.springframework.boot:org.springframework.boot.gradle.plugin", /* if packageName then display the depName */
"currentVersion": "2.7.2",
"newVersion": "2.7.3"
}
],
"gradleWrapperUpdates": [
{
"fileName": "gradle/wrapper/gradle-wrapper.properties",
"currentVersion": "7.5",
"newVersion": "7.5.1"
}
]
}
]
/* This is the input */
[
{
"randomKey": "this is not what I am looking for",
"otherFields": "other object that does not match the query"
},
{
"repository": "myRepositoryName",
"baseBranch": "master",
"config": {
"gradle": [
{
"packageFile": "gradle.properties",
"datasource": "maven",
"deps": []
},
{
"packageFile": "dependencies.gradle",
"datasource": "maven",
"deps": [
{
"depName": "packageName:dependencyName",
"currentValue": "0.8.0",
"managerData": {
"fileReplacePosition": 611,
"packageFile": "dependencies.gradle"
},
"fileReplacePosition": 611,
"registryUrls": [
"https://mavenCentral/repository/release",
"https://mavenCentral/repository/maven-mirror",
"https://mavenCentral/repository/gradle-plugins"
],
"depType": "dependencies",
"depIndex": 0,
"updates": [],
"warnings": [],
"versioning": "gradle",
"currentVersion": "0.8.0",
"fixedVersion": "0.8.0"
},
{
"depName": "packageName.api:feature-flags",
"currentValue": "0.20.0",
"managerData": {
"fileReplacePosition": 1118,
"packageFile": "dependencies.gradle"
},
"fileReplacePosition": 1118,
"registryUrls": [
"https://mavenCentral/repository/release",
"https://mavenCentral/repository/maven-mirror",
"https://mavenCentral/repository/gradle-plugins"
],
"depType": "dependencies",
"depIndex": 8,
"updates": [
{
"bucket": "non-major",
"newVersion": "0.21.0",
"newValue": "0.21.0",
"releaseTimestamp": "2022-08-25T04:57:50.000Z",
"newMajor": 0,
"newMinor": 21,
"updateType": "minor",
"branchName": "renovate/all-minor-patch"
}
],
"warnings": [],
"versioning": "gradle",
"currentVersion": "0.20.0",
"isSingleVersion": true,
"fixedVersion": "0.20.0"
},
{
"depName": "io.rest-assured:xml-path",
"currentValue": "4.5.1",
"managerData": {
"fileReplacePosition": 3307,
"packageFile": "dependencies.gradle"
},
"fileReplacePosition": 3307,
"registryUrls": [
"https://mavenCentral/repository/release",
"https://mavenCentral/repository/maven-mirror",
"https://mavenCentral/repository/gradle-plugins"
],
"depType": "dependencies",
"depIndex": 39,
"updates": [
{
"bucket": "major",
"newVersion": "5.1.1",
"newValue": "5.1.1",
"releaseTimestamp": "2022-06-10T06:46:14.000Z",
"newMajor": 5,
"newMinor": 1,
"updateType": "major",
"branchName": "renovate/io.rest-assured-xml-path-5.x"
}
],
"warnings": [],
"versioning": "gradle",
"sourceUrl": "http://svn.sonatype.org/spice/tags/oss-parent-5",
"homepage": "https://rest-assured.io/",
"currentVersion": "4.5.1",
"isSingleVersion": true,
"fixedVersion": "4.5.1"
},
{
"depName": "io.rest-assured:json-schema-validator",
"currentValue": "5.1.1",
"managerData": {
"fileReplacePosition": 3376,
"packageFile": "dependencies.gradle"
},
"fileReplacePosition": 3376,
"registryUrls": [
"https://mavenCentral/repository/release",
"https://mavenCentral/repository/maven-mirror",
"https://mavenCentral/repository/gradle-plugins"
],
"depType": "dependencies",
"depIndex": 40,
"updates": [],
"warnings": [],
"versioning": "gradle",
"sourceUrl": "http://svn.sonatype.org/spice/tags/oss-parent-5",
"homepage": "http://maven.apache.org",
"currentVersion": "5.1.1",
"fixedVersion": "5.1.1"
}
]
},
{
"packageFile": "settings.gradle",
"datasource": "maven",
"deps": []
},
{
"packageFile": "build.gradle",
"datasource": "maven",
"deps": [
{
"depType": "plugin",
"depName": "com.diffplug.spotless",
"packageName": "com.diffplug.spotless:com.diffplug.spotless.gradle.plugin",
"registryUrls": [
"https://mavenCentral/repository/release",
"https://mavenCentral/repository/maven-mirror",
"https://mavenCentral/repository/gradle-plugins",
"https://plugins.gradle.org/m2/"
],
"commitMessageTopic": "plugin com.diffplug.spotless",
"currentValue": "6.9.0",
"managerData": {
"fileReplacePosition": 50,
"packageFile": "build.gradle"
},
"fileReplacePosition": 50,
"depIndex": 0,
"updates": [
{
"bucket": "non-major",
"newVersion": "6.10.0",
"newValue": "6.10.0",
"releaseTimestamp": "2022-08-24T14:40:44.000Z",
"newMajor": 6,
"newMinor": 10,
"updateType": "minor",
"branchName": "renovate/all-minor-patch"
}
],
"warnings": [],
"versioning": "gradle",
"currentVersion": "6.9.0",
"isSingleVersion": true,
"fixedVersion": "6.9.0"
},
{
"depType": "plugin",
"depName": "docker-publish-convention",
"packageName": "docker-publish-convention:docker-publish-convention.gradle.plugin",
"registryUrls": [
"https://mavenCentral/repository/release",
"https://mavenCentral/repository/maven-mirror",
"https://mavenCentral/repository/gradle-plugins",
"https://plugins.gradle.org/m2/"
],
"commitMessageTopic": "plugin docker-publish-convention",
"currentValue": "latest.release",
"managerData": {
"fileReplacePosition": 158,
"packageFile": "build.gradle"
},
"fileReplacePosition": 158,
"depIndex": 2,
"updates": [],
"warnings": [],
"versioning": "gradle",
"skipReason": "invalid-value"
},
{
"depType": "plugin",
"depName": "org.springframework.boot",
"packageName": "org.springframework.boot:org.springframework.boot.gradle.plugin",
"registryUrls": [
"https://mavenCentral/repository/release",
"https://mavenCentral/repository/maven-mirror",
"https://mavenCentral/repository/gradle-plugins",
"https://plugins.gradle.org/m2/"
],
"commitMessageTopic": "plugin org.springframework.boot",
"currentValue": "2.7.2",
"managerData": {
"fileReplacePosition": 217,
"packageFile": "build.gradle"
},
"fileReplacePosition": 217,
"depIndex": 3,
"updates": [
{
"bucket": "non-major",
"newVersion": "2.7.3",
"newValue": "2.7.3",
"releaseTimestamp": "2022-08-18T06:30:12.000Z",
"newMajor": 2,
"newMinor": 7,
"updateType": "patch",
"branchName": "renovate/all-minor-patch"
}
],
"warnings": [],
"versioning": "gradle",
"sourceUrl": "https://github.com/spring-projects/spring-boot",
"homepage": "https://spring.io/projects/spring-boot",
"currentVersion": "2.7.2",
"isSingleVersion": true,
"fixedVersion": "2.7.2"
}
]
}
],
"gradle-wrapper": [
{
"packageFile": "gradle/wrapper/gradle-wrapper.properties",
"deps": [
{
"depName": "gradle",
"currentValue": "7.5",
"replaceString": "https\\://mavenCentral/repository/gradle-dist/gradle-7.5-bin.zip",
"datasource": "gradle-version",
"versioning": "gradle",
"depIndex": 0,
"updates": [
{
"bucket": "non-major",
"newVersion": "7.5.1",
"newValue": "7.5.1",
"releaseTimestamp": "2022-08-05T21:17:56.000Z",
"newMajor": 7,
"newMinor": 5,
"updateType": "patch",
"branchName": "renovate/all-minor-patch"
}
],
"warnings": [],
"sourceUrl": "https://github.com/gradle/gradle",
"homepage": "https://gradle.org",
"currentVersion": "7.5",
"isSingleVersion": true,
"fixedVersion": "7.5"
}
]
}
]
}
}
]
With some assumptions made for the edge cases, this should meet your requirements:
map(select(has("baseBranch") and .config != {}) | {
repository,
numberOfUpdates: 0,
gradleUpdates: .config.gradle,
gradleWrapperUpdates: .config."gradle-wrapper"
} | (.gradleUpdates, .gradleWrapperUpdates) |= map(
.packageFile as $fileName | .deps[] | .updates[] as $update | {
$fileName,
package: (.packageName // .depName),
currentVersion,
newVersion: $update.newValue
})
| .numberOfUpdates += ([.gradleUpdates, .gradleWrapperUpdates | length] | add)
)
[
{
"repository": "myRepositoryName",
"numberOfUpdates": 5,
"gradleUpdates": [
{
"fileName": "dependencies.gradle",
"package": "packageName.api:feature-flags",
"currentVersion": "0.20.0",
"newVersion": "0.21.0"
},
{
"fileName": "dependencies.gradle",
"package": "io.rest-assured:xml-path",
"currentVersion": "4.5.1",
"newVersion": "5.1.1"
},
{
"fileName": "build.gradle",
"package": "com.diffplug.spotless:com.diffplug.spotless.gradle.plugin",
"currentVersion": "6.9.0",
"newVersion": "6.10.0"
},
{
"fileName": "build.gradle",
"package": "org.springframework.boot:org.springframework.boot.gradle.plugin",
"currentVersion": "2.7.2",
"newVersion": "2.7.3"
}
],
"gradleWrapperUpdates": [
{
"fileName": "gradle/wrapper/gradle-wrapper.properties",
"package": "gradle",
"currentVersion": "7.5",
"newVersion": "7.5.1"
}
]
}
]
Demo

How to edit rows in detailslist fluent react UI

I am working with Fluent react UI. I want to edit rows in the table. Is there any option?
https://developer.microsoft.com/en-us/fluentui#/controls/web/detailslist
I recommend FluentUI Editable DetailsList. The following example/library has excellent customization to edit on grid/table. It also have other features like column-based filter, bulk edit, bulk delete, and so on.
GitHub Repo: https://github.com/microsoft/FluentUIEditableDetailsList
Working Example: https://editabledetailslist.azurewebsites.net/
The examples are right forward and easy to use. I am currently using it in my SPFx Webpart project with react. You can install using the npm and use the example on the repository to play around.
Install Package on your project
npm i fluentui-editable-grid
Usage
import { DetailsListLayoutMode, mergeStyles, mergeStyleSets, SelectionMode, TextField } from '#fluentui/react';
import { EditableGrid, EditControlType, IColumnConfig, EventEmitter, EventType, NumberAndDateOperators } from 'fluentui-editable-grid';
import { Fabric } from 'office-ui-fabric-react';
import * as React from 'react';
import { useState } from 'react';
const Consumer = () => {
const classNames = mergeStyleSets({
controlWrapper: {
display: 'flex',
flexWrap: 'wrap',
}
});
const [items, setItems] = useState<any[]>([]);
const columns: IColumnConfig[] = [
{
key: 'id',
name: 'ID',
text: 'ID',
editable: false,
dataType: 'number',
minWidth: 100,
maxWidth: 100,
isResizable: true,
includeColumnInExport: true,
includeColumnInSearch: true,
applyColumnFilter: true,
disableSort: true
},
{
key: 'customerhovercol',
name: 'Custom Hover Column',
text: 'Custom Hover Column',
editable: true,
dataType: 'string',
minWidth: 100,
maxWidth: 100,
isResizable: true,
includeColumnInExport: false,
includeColumnInSearch: false,
applyColumnFilter: false,
disableSort: true,
hoverComponentOptions: { enable:true, hoverChildComponent: <CellHover customProps={{ someProp: '' }} /> }
},
{
key: 'name',
name: 'Name',
text: 'Name',
editable: true,
dataType: 'string',
minWidth: 100,
maxWidth: 100,
isResizable: true,
includeColumnInExport: true,
includeColumnInSearch: true,
applyColumnFilter: true
},
{
key: 'age',
name: 'Age',
text: 'Age',
editable: true,
dataType: 'number',
minWidth: 100,
maxWidth: 100,
isResizable: true,
includeColumnInExport: true,
includeColumnInSearch: true,
applyColumnFilter: true
},
{
key: 'designation',
name: 'Designation',
text: 'Designation',
editable: true,
dataType: 'string',
minWidth: 100,
maxWidth: 100,
isResizable: true,
includeColumnInExport: true,
includeColumnInSearch: true,
inputType: EditControlType.MultilineTextField,
applyColumnFilter: true
},
{
key: 'salary',
name: 'Salary',
text: 'Salary',
editable: true,
dataType: 'number',
minWidth: 100,
maxWidth: 100,
isResizable: true,
includeColumnInExport: false,
includeColumnInSearch: true,
maxLength:5,
applyColumnFilter: true,
cellStyleRule: {
enable: true,
rule: {
operator : NumberAndDateOperators.LESSTHAN,
value: 50000
},
whenTrue: { textColor: '#EF5350', fontWeight: 'bold' },
whenFalse: { textColor: '#9CCC65' }
}
},
{
key: 'dateofjoining',
name: 'Date of Joining',
text: 'Date of Joining',
editable: true,
dataType: 'date',
minWidth: 150,
maxWidth: 150,
isResizable: true,
includeColumnInExport: true,
includeColumnInSearch: true,
inputType: EditControlType.Date
},
{
key: 'payrolltype',
name: 'Payroll Type',
text: 'Payroll Type',
editable: true,
dataType: 'string',
minWidth: 150,
maxWidth: 150,
isResizable: true,
includeColumnInExport: true,
includeColumnInSearch: true,
inputType: EditControlType.DropDown,
dropdownValues: [
{ key: 'weekly', text: 'Weekly' },
{ key: 'biweekly', text: 'Bi-Weekly' },
{ key: 'monthly', text: 'Monthly' }
]
},
{
key: 'employmenttype',
name: 'Employment Type',
text: 'Employment Type',
editable: true,
dataType: 'string',
minWidth: 200,
maxWidth: 200,
isResizable: true,
includeColumnInExport: true,
includeColumnInSearch: true,
inputType: EditControlType.Picker,
pickerOptions: {
pickerTags: ['Employment Type1', 'Employment Type2', 'Employment Type3', 'Employment Type4', 'Employment Type5', 'Employment Type6', 'Employment Type7', 'Employment Type8', 'Employment Type9', 'Employment Type10', 'Employment Type11', 'Employment Type12'],
minCharLimitForSuggestions: 2,
tagsLimit: 1,
pickerDescriptionOptions: {
enabled: true,
values: [
{ key: 'Employment Type1', description: 'Employment Type1 Description'},
{ key: 'Employment Type2', description: 'Employment Type2 Description'},
{ key: 'Employment Type3', description: 'Employment Type3 Description'},
{ key: 'Employment Type4', description: 'Employment Type4 Description'},
{ key: 'Employment Type5', description: 'Employment Type5 Description'},
{ key: 'Employment Type6', description: 'Employment Type6 Description'},
{ key: 'Employment Type7', description: 'Employment Type7 Description'},
{ key: 'Employment Type8', description: 'Employment Type8 Description'},
{ key: 'Employment Type9', description: 'Employment Type9 Description'},
{ key: 'Employment Type10', description: 'Employment Type10 Description'},
{ key: 'Employment Type11', description: 'Employment Type11 Description'},
{ key: 'Employment Type12', description: 'Employment Type12 Description'},
] },
suggestionsRule: StringOperators.STARTSWITH
}
}
];
const SetDummyData = () : void => {
const dummyData = [
{
id: "1",
customerhovercol: 'Hover Me',
name: "Name1",
age:32,
designation:'Designation1',
salary:57000,
dateofjoining:'2010-04-01T14:57:10',
payrolltype: 'Weekly',
employmenttype: 'Employment Type11'
},
{
id: "2",
customerhovercol: 'Hover Me',
name: "Name2",
age:27,
designation:'Designation2',
salary:42000,
dateofjoining:'2014-06-09T14:57:10',
payrolltype: 'Monthly',
employmenttype: 'Employment Type4'
},
{
id: "3",
customerhovercol: 'Hover Me',
name: "Name3",
age:35,
designation:'Designation3',
salary:75000,
dateofjoining:'2005-07-02T14:57:10',
payrolltype: 'Weekly',
employmenttype: 'Employment Type7'
},
{
id: "4",
customerhovercol: 'Hover Me',
name: "Name4",
age:30,
designation:'Designation4',
salary:49000,
dateofjoining:'2019-04-01T14:57:10',
payrolltype: 'Bi-Weekly',
employmenttype: 'Employment Type2'
}
];
setItems(dummyData);
}
React.useEffect(() => {
SetDummyData();
}, []);
return (
<Fabric>
<div className={classNames.controlWrapper}>
<TextField placeholder='Search Grid' className={mergeStyles({ width: '60vh', paddingBottom:'10px' })} onChange={(event) => EventEmitter.dispatch(EventType.onSearch, event)}/>
</div>
<EditableGrid
id={1}
columns={columns}
items={items}
enableCellEdit={true}
enableExport={true}
enableTextFieldEditMode={true}
enableTextFieldEditModeCancel={true}
enableGridRowsDelete={true}
enableGridRowsAdd={true}
height={'70vh'}
width={'140vh'}
position={'relative'}
enableUnsavedEditIndicator={true}
//onGridSave={onGridSave}
enableGridReset={true}
enableColumnFilters={true}
enableColumnFilterRules={true}
enableRowAddWithValues={{enable : true, enableRowsCounterInPanel : true}}
layoutMode={DetailsListLayoutMode.justified}
selectionMode={SelectionMode.multiple}
enableRowEdit={true}
enableRowEditCancel={true}
enableBulkEdit={true}
enableColumnEdit={true}
enableSave={true}
/>
</Fabric>
);
};
export default Consumer;
}

Querying Vertices through another vertex [GREMLIN]

The image above is how my graph looks like, and i would like to query the following output:
[
{
chart:{
name: 'chart1',
id: 'chart1',
label: 'chart',
pk: 'chart1',
},
variables: [
{
variable: {
name:'variable1'
id: 'variable1',
label: 'variable',
pk: 'variable1',
},
years: [
{
name:'year1'
id: 'year1',
label: 'year',
pk: 'year1',
},
{
name:'year2'
id: 'year2',
label: 'year',
pk: 'year2',
},
],
},
{
variable: {
name:'variable2'
id: 'variable2',
label: 'variable',
pk: 'variable2',
},
years: [
{
name:'year3'
id: 'year3',
label: 'year',
pk: 'year3',
},
],
}
],
},
{
chart:{
name: 'chart2',
id: 'chart2',
label: 'chart',
pk: 'chart2',
},
variables: [
{
variable: {
name:'variable2'
id: 'variable2',
label: 'variable',
pk: 'variable2',
},
years: [
{
name:'year4'
id: 'year4',
label: 'year',
pk: 'year4',
},
],
},
],
}
]
But with my current query:
g
.V()
.hasLabel('chart')
.project('chart', 'variables')
.by(valueMap(true))
.by(
out('visualizes')
.hasLabel('year')
.out('outputs')
.hasLabel('variable')
.project('variable', 'years')
.by(
valueMap(true).fold()
)
.by(
__.in('outputs')
.hasLabel('year')
.valueMap(true)
.fold()
)
.fold()
)
This is what im getting:
[
{
chart: {
id: 'chart1',
label: 'chart',
name: 'chart1',
pk: 'chart1',
},
variables: [
{
variable: [
{
id: 'variable1',
label: variable,
name: 'variable1',
pk: 'variable1'
}
],
years: [
{
id: 'year1',
label: 'year',
name: 'year1',
pk: 'year1',
},
{
id: 'year2',
label: "year",
name: 'year2',
pk: 'year2'
},
]
},
{
variable: [
{
id: 'variable1',
label: 'variable',
name: 'variable1',
'pk': 'variable1'
}
],
years: [
{
id: 'year1',
label: 'year',
name: 'year1',
pk: 'year1'
},
{
id: 'year2',
label: 'year',
name: 'year2',
pk: 'year2'
}
]
},
{
variable: [
{
id: 'variable2',
label: "variable",
name: 'variable2',
pk: 'variable2'
}
],
years: [
{
id: 'year3',
label: 'year',
name: 'year3',
pk: 'year3',
},
{
id: 'year4',
label: "year",
name: 'year4',
pk: 'year4'
}
]
}
]
},
{
chart: {
id: 'chart2',
label: 'chart',
name: 'chart2',
pk: 'chart2'
},
variables: [
{
variable: [
{
id: 'variable2',
label: 'variable',
name: 'variable2',
pk: 'variable2'
}
],
years: [
{
id: 'year3',
label: 'year',
name: 'year3',
pk: 'year3'
},
{
id: 'year4',
label: 'year',
name: 'year4',
pk: 'year4'
}
]
}
]
}
]
//this is the formatted version to be easily read. refer to this link for the actual json: https://pastebin.com/Y2ncHyPi
As you can see from the actual output my problem with the query, is chart1 duplicates variable1 and chart2's variable have year3 which is from chart1. Do i have to change the structure of my graph? or do i have to add additional properties for reference? please help.
Query for seeding graph:
g
.addV('chart')
.property('name', 'chart1')
.property('pk', 'chart1')
.property('id', 'chart1')
.as('chart1')
.addV('chart')
.property('name', 'chart2')
.property('pk', 'chart2')
.property('id', 'chart2')
.as('chart2')
.addV('year')
.property('name', 'year1')
.property('pk', 'year1')
.property('id', 'year1')
.as('year1')
.addV('year')
.property('name', 'year2')
.property('pk', 'year2')
.property('id', 'year2')
.as('year2')
.addV('year')
.property('name', 'year3')
.property('pk', 'year3')
.property('id', 'year3')
.as('year3')
.addV('year')
.property('name', 'year4')
.property('pk', 'year4')
.property('id', 'year4')
.as('year4')
.addV('variable')
.property('name', 'variable1')
.property('pk', 'variable1')
.property('id', 'variable1')
.as('variable1')
.addV('variable')
.property('name', 'variable2')
.property('pk', 'variable2')
.property('id', 'variable2')
.as('variable2')
.addE('visualizes')
.from('chart1')
.to('year1')
.addE('outputs')
.from('year1')
.to('variable1')
.addE('visualizes')
.from('chart1')
.to('year2')
.addE('outputs')
.from('year2')
.to('variable1')
.addE('visualizes')
.from('chart1')
.to('year3')
.addE('outputs')
.from('year3')
.to('variable2')
.addE('visualizes')
.from('chart2')
.to('year4')
.addE('outputs')
.from('year4')
.to('variable2')
PS: I am using Azure Cosmos DB's gremlin API.
I can suggest a solution that I'm not sure is the simplest one, but it works:
g.V().hasLabel('chart').
project('chart', 'variables').
by(valueMap(true)).
by(out('visualizes').
hasLabel('year').as('y').
out('outputs').
group().by().
by(select('y').fold()).unfold().
project('variable', 'years').
by(select(keys).
valueMap(true)).
by(select(values).unfold().
valueMap(true).fold()).fold())
I tested it here:
https://gremlify.com/6h

How can i Merge/Summaries two JSON array into one based on one key variable in R?

I have some JSON arrays as -
"expenseRecords": [
{
"date_expensed": "2019-04-01",
"exp_cat_description": "Air Travel",
"totalamountUSD": 10,
"totalRecords": 2
},
{
"date_expensed": "2019-04-01",
"exp_cat_description": "Breakfast",
"totalamountUSD": 11,
"totalRecords": 1
}]
And my desired format is
"expenseRecords": [
{
"date_expensed": "2019-04-01",{
"exp_cat_description": "Air Travel",
"totalamountUSD": 10,
"totalRecords": 2
},
{
"exp_cat_description": "Breakfast",
"totalamountUSD": 11,
"totalRecords": 1
}, ]
How to achieve this in R
let newarray =[]
const object1 = {
name: 'Flavio'
}
const object2 = {
age: 35
}
const object3 = {...object1, ...object2 }
newArray=[...newArray,object3]
You could use the jsonlite library and the split data.frame fonction.
First convert your json to an R object than split the data.frame by the variable and then rewrite the json object.
inputjson <- '{"expenseRecords": [ { "date_expensed": "2019-04-01", "exp_cat_description": "Air Travel", "totalamountUSD": 10, "totalRecords": 2 }, { "date_expensed": "2019-04-01", "exp_cat_description": "Breakfast", "totalamountUSD": 11, "totalRecords": 1 },{ "date_expensed": "2019-04-02", "exp_cat_description": "Air Travel", "totalamountUSD": 10, "totalRecords": 2 }]}'
library(jsonlite)
input <- fromJSON(inputjson)
input$expenseRecords <- split(input$expenseRecords[,-1], input$expenseRecords$date_expensed)
output <- toJSON(input)

Moment.js doesn't show correct time

When running my node.js project locally on my computer, moment.js is showing correct time (2019-10-28T07:00:00.000Z because moment have adjusted for DST +02:00 in april and +01:00 in october)):
Moment {
_isAMomentObject: true,
_i: '2019-04-15T06:00:00.000Z',
_f: 'YYYY-MM-DDTHH:mm:ss.SSSSZ',
_tzm: 0,
_isUTC: false,
_pf:
{ empty: false,
unusedTokens: [],
unusedInput: [],
overflow: -1,
charsLeftOver: 0,
nullInput: false,
invalidMonth: null,
invalidFormat: false,
userInvalidated: false,
iso: true,
parsedDateParts: [ 2019, 3, 15, 6, 0, 0, 0 ],
meridiem: undefined,
rfc2822: false,
weekdayMismatch: false },
_locale:
Locale {
_calendar:
{ sameDay: '[Today at] LT',
nextDay: '[Tomorrow at] LT',
nextWeek: 'dddd [at] LT',
lastDay: '[Yesterday at] LT',
lastWeek: '[Last] dddd [at] LT',
sameElse: 'L' },
_longDateFormat:
{ LTS: 'h:mm:ss A',
LT: 'h:mm A',
L: 'MM/DD/YYYY',
LL: 'MMMM D, YYYY',
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A' },
_invalidDate: 'Invalid date',
ordinal: [Function: ordinal],
_dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
_relativeTime:
{ future: 'in %s',
past: '%s ago',
s: 'a few seconds',
ss: '%d seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years' },
_months:
[ 'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December' ],
_monthsShort:
[ 'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec' ],
_week: { dow: 0, doy: 6 },
_weekdays:
[ 'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday' ],
_weekdaysMin: [ 'Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa' ],
_weekdaysShort: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
_meridiemParse: /[ap]\.?m?\.?/i,
_abbr: 'en',
_config:
{ calendar: [Object],
longDateFormat: [Object],
invalidDate: 'Invalid date',
ordinal: [Function: ordinal],
dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
relativeTime: [Object],
months: [Array],
monthsShort: [Array],
week: [Object],
weekdays: [Array],
weekdaysMin: [Array],
weekdaysShort: [Array],
meridiemParse: /[ap]\.?m?\.?/i,
abbr: 'en' },
_dayOfMonthOrdinalParseLenient: /\d{1,2}(th|st|nd|rd)|\d{1,2}/ },
_a: [ 2019, 3, 15, 6, 0, 0, 0 ],
_d: 2019-10-28T07:00:00.000Z,
_isValid: true,
_z: null }
But on my server, I get this:
Moment {
_isAMomentObject: true,
_i: '2019-04-15T06:00:00.000Z',
_f: 'YYYY-MM-DDTHH:mm:ss.SSSSZ',
week: [Object],
weekdays: [Array],
weekdaysMin: [Array],
weekdaysShort: [Array],
meridiemParse: /[ap]\.?m?\.?/i,
abbr: 'en' },
_dayOfMonthOrdinalParseLenient: /\d{1,2}(th|st|nd|rd)|\d{1,2}/ },
_a: [ 2019, 3, 15, 6, 0, 0, 0 ],
_d: 2019-10-28T06:00:00.000Z,
_isValid: true,
_z: null }
The date is incorrectly set to 2019-10-28T06:00:00:000Z.
I have set the timezone on the server with sudo timedatectl set-timezone Europe/Oslo
If I am using moment.isDST() for dates on the server, it correctly gives my true in April and false in October.
I am unsure how to solve this, on the server or in my code?
I think I solved it. By answering the from Styx questions, I finally realized that the server app running in a docker container didn't have the correct timezone. By setting environment: TZ: "Europe/Oslo" in the docker-compose.yml file this fixed the problem, and I am getting correct time now.

Resources