Node red write double word - double

How do I convert number to double word in Node-red?
I tried throwing the array in
but no response
I'm not very good at node red, please answer me, thank you

What do you mean converting 'number' to 'double word'?
Data type 'double' is already number type.
Do you mean String to number?
[
{
"id": "bd8884d5c2f82322",
"type": "tab",
"label": "플로우 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "4546977fe7434e95",
"type": "inject",
"z": "bd8884d5c2f82322",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1234.34",
"payloadType": "str",
"x": 160,
"y": 40,
"wires": [
[
"a93489fbd55883b2",
"f1ad7ec076bceb78"
]
]
},
{
"id": "a93489fbd55883b2",
"type": "function",
"z": "bd8884d5c2f82322",
"name": "Convert String to Number",
"func": "msg.payload=Number(msg.payload);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 40,
"wires": [
[
"1f695a58ebc55f90"
]
]
},
{
"id": "1f695a58ebc55f90",
"type": "debug",
"z": "bd8884d5c2f82322",
"name": "number",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 560,
"y": 40,
"wires": []
},
{
"id": "f1ad7ec076bceb78",
"type": "debug",
"z": "bd8884d5c2f82322",
"name": "string",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 310,
"y": 80,
"wires": []
}]

Related

How to add json data in ConfigMap creation in ArgoCD

I'm trying to create a ConfigMap with ArgoCD.
I've created a volumes.yaml file as such
---
apiVersion: v1
kind: ConfigMap
metadata:
name: persistent-volumes-argo
labels:
grafana_dashboard: "1"
project: "foo"
data:
kubernetes.json: |
{{ .Files.Get "dashboards/persistent-volumes.json" | indent 4 }}
But ArgoCD doesn't seem to be able to read the data, the way a standard Helm deployment would.
I've tried adding the data directly into the ConfigMap as such
(Data omitted for brevity)
---
apiVersion: v1
kind: ConfigMap
metadata:
name: persistent-volumes-argo
labels:
grafana_dashboard: "1"
project: "foo"
data:
kubernetes.json: |
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"limit": 100,
"name": "Annotations & Alerts",
"showIn": 0,
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": 13646,
"graphTooltip": 0,
"iteration": 1659421503107,
"links": [],
"panels": [
{
"collapsed": false,
"datasource": null,
"fieldConfig": {
"defaults": {},
"overrides": []
},
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"id": 26,
"panels": [],
"title": "Alerts",
"type": "row"
},
{
"datasource": "$datasource",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"noValue": "--",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "semi-dark-red",
"value": null
},
{
"color": "light-green",
"value": -0.0001
},
{
"color": "semi-dark-red",
"value": 0.0001
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 8,
"x": 0,
"y": 1
},
"id": 21,
"options": {
"colorMode": "background",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": false
},
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.0.3",
"targets": [
{
"expr": "count (max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes{namespace=~\"${k8s_namespace}\"} ) and (max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes{namespace=~\"${k8s_namespace}\"} )) / (max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_capacity_bytes{namespace=~\"${k8s_namespace}\"} )) >= (${warning_threshold} / 100)) or vector (0)",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "PVCs Above Warning Threshold",
"type": "stat"
},
{
"datasource": "$datasource",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"decimals": 0,
"mappings": [],
"noValue": "--",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "semi-dark-red",
"value": null
},
{
"color": "light-green",
"value": -0.0001
},
{
"color": "semi-dark-red",
"value": 0.0001
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 8,
"x": 8,
"y": 1
},
"id": 24,
"options": {
"colorMode": "background",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": false
},
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.0.3",
"targets": [
{
"expr": "count((kube_persistentvolumeclaim_status_phase{namespace=~\"${k8s_namespace}\",phase=\"Pending\"}==1)) or vector(0)",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "PVCs in Pending State",
"transformations": [
{
"id": "organize",
"options": {}
}
],
"type": "stat"
},
{
"datasource": "$datasource",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"decimals": 0,
"mappings": [],
"noValue": "--",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "semi-dark-red",
"value": null
},
{
"color": "light-green",
"value": -0.0001
},
{
"color": "semi-dark-red",
"value": 0.0001
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 8,
"x": 16,
"y": 1
},
"id": 23,
"options": {
"colorMode": "background",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": false
},
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.0.3",
"targets": [
{
"expr": "count((kube_persistentvolumeclaim_status_phase{namespace=~\"${k8s_namespace}\",phase=\"Lost\"}==1)) or vector(0)",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "PVCs in Lost State",
"transformations": [
{
"id": "organize",
"options": {}
}
],
"type": "stat"
},
{
"collapsed": false,
"datasource": null,
"fieldConfig": {
"defaults": {},
"overrides": []
},
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 5
},
"id": 17,
"panels": [],
"title": "Usage statistics",
"type": "row"
},
{
"datasource": "$datasource",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"align": null,
"displayMode": "auto",
"filterable": false
},
"mappings": [],
"noValue": "--",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "light-green",
"value": null
}
]
},
"unit": "none"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "Used (%)"
},
"properties": [
{
"id": "custom.displayMode",
"value": "gradient-gauge"
},
{
"id": "thresholds",
"value": {
"mode": "absolute",
"steps": [
{
"color": "light-green",
"value": null
},
{
"color": "semi-dark-yellow",
"value": 70
},
{
"color": "dark-red",
"value": 80
}
]
}
},
{
"id": "decimals",
"value": 1
}
]
},
{
"matcher": {
"id": "byName",
"options": "Status"
},
"properties": [
{
"id": "custom.displayMode",
"value": "color-background"
},
{
"id": "mappings",
"value": [
{
"options": {
"0": {
"text": "Bound"
},
"1": {
"text": "Pending"
},
"2": {
"text": "Lost"
}
},
"type": "value"
}
]
},
{
"id": "thresholds",
"value": {
"mode": "absolute",
"steps": [
{
"color": "light-green",
"value": null
},
{
"color": "light-green",
"value": 0
},
{
"color": "semi-dark-orange",
"value": 1
},
{
"color": "semi-dark-red",
"value": 2
}
]
}
},
{
"id": "noValue",
"value": "--"
},
{
"id": "custom.align",
"value": "center"
}
]
},
{
"matcher": {
"id": "byName",
"options": "Namespace"
},
"properties": [
{
"id": "custom.width",
"value": 120
}
]
},
{
"matcher": {
"id": "byName",
"options": "Status"
},
"properties": [
{
"id": "custom.width",
"value": 80
}
]
},
{
"matcher": {
"id": "byName",
"options": "Capacity (GiB)"
},
"properties": [
{
"id": "custom.width",
"value": 120
}
]
},
{
"matcher": {
"id": "byName",
"options": "Used (GiB)"
},
"properties": [
{
"id": "custom.width",
"value": 120
}
]
},
{
"matcher": {
"id": "byName",
"options": "Available (GiB)"
},
"properties": [
{
"id": "custom.width",
"value": 120
}
]
},
{
"matcher": {
"id": "byName",
"options": "StorageClass"
},
"properties": [
{
"id": "custom.width",
"value": 150
}
]
},
{
"matcher": {
"id": "byName",
"options": "PersistentVolumeClaim"
},
"properties": [
{
"id": "custom.width",
"value": 370
}
]
}
]
},
"gridPos": {
"h": 12,
"w": 24,
"x": 0,
"y": 6
},
"id": 29,
"interval": "",
"options": {
"frameIndex": 2,
"showHeader": true,
"sortBy": [
{
"desc": false,
"displayName": "PersistentVolumeClaim"
}
]
},
"pluginVersion": "8.0.3",
"targets": [
{
"expr": " sum by (persistentvolumeclaim,namespace,storageclass,volumename) (kube_persistentvolumeclaim_info{namespace=~\"${k8s_namespace}\"})",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "A"
},
{
"expr": "sum by (persistentvolumeclaim) (kubelet_volume_stats_capacity_bytes{namespace=~\"${k8s_namespace}\"}/1024/1024/1024)",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "B"
},
{
"expr": "sum by (persistentvolumeclaim) (kubelet_volume_stats_used_bytes{namespace=~\"${k8s_namespace}\"}/1024/1024/1024)",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "C"
},
{
"expr": "sum by (persistentvolumeclaim) (kubelet_volume_stats_available_bytes{namespace=~\"${k8s_namespace}\"}/1024/1024/1024)",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "D"
},
{
"expr": "sum(kube_persistentvolumeclaim_status_phase{namespace=~\"${k8s_namespace}\",phase=~\"(Pending|Lost)\"}) by (persistentvolumeclaim) + sum(kube_persistentvolumeclaim_status_phase{namespace=~\"${k8s_namespace}\",phase=~\"(Lost)\"}) by (persistentvolumeclaim)",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "E"
},
{
"expr": "sum by (persistentvolumeclaim) (kubelet_volume_stats_used_bytes{namespace=~\"${k8s_namespace}\"}/kubelet_volume_stats_capacity_bytes{namespace=~\"${k8s_namespace}\"} * 100)",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "",
"refId": "F"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Persistent Volume Claim",
"transformations": [
{
"id": "seriesToColumns",
"options": {
"byField": "persistentvolumeclaim"
}
},
{
"id": "organize",
"options": {
"excludeByName": {
"Time": true,
"Time 1": true,
"Time 2": true,
"Time 3": true,
"Time 4": true,
"Time 5": true,
"Time 6": true,
"Value #A": true
},
"indexByName": {},
"renameByName": {
"Time 1": "",
"Time 2": "",
"Time 3": "",
"Time 4": "",
"Time 5": "",
"Time 6": "",
"Value #A": "",
"Value #B": "Capacity (GiB)",
"Value #C": "Used (GiB)",
"Value #D": "Available (GiB)",
"Value #E": "Status",
"Value #F": "Used (%)",
"namespace": "Namespace",
"persistentvolumeclaim": "PersistentVolumeClaim",
"storageclass": "StorageClass",
"volumename": "PhysicalVolume"
}
}
}
],
"type": "table"
},
{
"datasource": "$datasource",
"fieldConfig": {
"defaults": {
"custom": {
"align": null,
"displayMode": "auto",
"filterable": false
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 5,
"w": 24,
"x": 0,
"y": 18
},
"id": 7,
"options": {
"showHeader": true,
"sortBy": [
{
"desc": true,
"displayName": "Status"
}
]
},
"pluginVersion": "8.0.3",
"targets": [
{
"expr": "kube_storageclass_info",
"format": "table",
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Storage Class",
"transformations": [
{
"id": "organize",
"options": {
"excludeByName": {
"Time": true,
"Value": true,
"__name__": true,
"app_kubernetes_io_instance": true,
"app_kubernetes_io_name": true,
"instance": true,
"job": true,
"kubernetes_namespace": true,
"kubernetes_pod_name": true,
"pod_template_hash": true
},
"indexByName": {
"Time": 1,
"Value": 13,
"__name__": 2,
"app_kubernetes_io_instance": 3,
"app_kubernetes_io_name": 4,
"instance": 5,
"job": 6,
"kubernetes_namespace": 7,
"kubernetes_pod_name": 8,
"pod_template_hash": 9,
"provisioner": 10,
"reclaimPolicy": 11,
"storageclass": 0,
"volumeBindingMode": 12
},
"renameByName": {
"provisioner": "Provisioner",
"reclaimPolicy": "ReclaimPolicy",
"storageclass": "StorageClass",
"volumeBindingMode": "VolumeBindingMode"
}
}
},
{
"id": "groupBy",
"options": {
"fields": {
"Provisioner": {
"aggregations": [],
"operation": "groupby"
},
"ReclaimPolicy": {
"aggregations": [],
"operation": "groupby"
},
"StorageClass": {
"aggregations": [],
"operation": "groupby"
},
"VolumeBindingMode": {
"aggregations": [],
"operation": "groupby"
}
}
}
}
],
"type": "table"
},
{
"collapsed": false,
"datasource": null,
"fieldConfig": {
"defaults": {},
"overrides": []
},
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 23
},
"id": 15,
"panels": [],
"title": "Graphical usage data ",
"type": "row"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "$datasource",
"fill": 0,
"fillGradient": 0,
"gridPos": {
"h": 12,
"w": 24,
"x": 0,
"y": 24
},
"hiddenSeries": false,
"id": 9,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "8.0.3",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "(max by (persistentvolumeclaim,namespace) (kubelet_volume_stats_used_bytes{namespace=~\"${k8s_namespace}\"}))",
"interval": "",
"legendFormat": "{{namespace}} ({{persistentvolumeclaim}})",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "All Running PVCs Used Bytes",
"tooltip": {
"shared": true,
"sort": 2,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "Date & time",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"collapsed": true,
"datasource": null,
"fieldConfig": {
"defaults": {},
"overrides": []
},
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 36
},
"id": 19,
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "$datasource",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 0,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 24,
"x": 0,
"y": 41
},
"hiddenSeries": false,
"id": 11,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": false,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.2.1",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "rate(kubelet_volume_stats_used_bytes{namespace=~\"${k8s_namespace}\"}[1h])",
"instant": false,
"interval": "",
"legendFormat": "{{namespace}} ({{persistentvolumeclaim}})",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Hourly Volume Usage Rate",
"tooltip": {
"shared": true,
"sort": 2,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "binBps",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "Date & time",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "$datasource",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 0,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 24,
"x": 0,
"y": 48
},
"hiddenSeries": false,
"id": 12,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": false,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.2.1",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "rate(kubelet_volume_stats_used_bytes{namespace=~\"${k8s_namespace}\"}[1d])",
"interval": "",
"legendFormat": "{{namespace}} ({{persistentvolumeclaim}})",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Daily Volume Usage Rate",
"tooltip": {
"shared": true,
"sort": 2,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "binBps",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "Date & time",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "$datasource",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 0,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 24,
"x": 0,
"y": 55
},
"hiddenSeries": false,
"id": 13,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": false,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
}
}
But this errors with rpc error: code = FailedPrecondition desc = Failed to unmarshal "volumes.yaml": <nil>
Is there a way to pass in json data when creating a ConfigMap with ArgoCD, either as a template or by dumping the data in the file?
To create configmap with argocd and helm
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "helm-chart.fullname" . }}-configmap
data:
config.json : |
{{ toJson .Values.configmap | indent 4 }}
and the value file should be like this, which is our JSON but converted to YAML
configmap:
json:
- rigid
- better for data interchange
yaml:
- slim and flexible
- better for configuration
object:
key: value
array:
- null_value:
- boolean: true
- integer: 1
- alias: &example aliases are like variables
- alias: *example
paragraph: >
Blank lines denote
paragraph breaks
content: |-
Or we
can auto
convert line breaks
to save space
alias: &foo
bar: baz
alias_reuse: *foo
json2yaml
A complete demo app can be found here
A very quick way to create app with the above configmap and demo app
argocd app create demo-app --repo https://github.com/Adiii717/argocd-demo-app.git --path helm-chart --dest-namespace default --dest-server https://kubernetes.default.svc --helm-set replicaCount=2
Make sure you also set
export ARGOCD_AUTH_TOKEN="tokeh
export ARGOCD_OPTS="--grpc-web"
export ARGOCD_SERVER="argocd.example.com"
added section for the configmap

How to get all the files from the Moodle assignment in a course?

I want to get all the files from an assignment in Moodle. Is there a way to get all the files?
When I call core_course_get_contents from my local Moodle instance as
http://localhost:8077/webservice/rest/server.php?wstoken=11e2d8b7f8e21ca1804e41e9cac5a816&wsfunction=core_course_get_contents&courseid=4&moodlewsrestformat=json
I receive the response as:
[
{
"id": 22,
"name": "General",
"visible": 1,
"summary": "",
"summaryformat": 1,
"section": 0,
"hiddenbynumsections": 0,
"uservisible": true,
"modules": []
},
{
"id": 23,
"name": "Introduction",
"visible": 1,
"summary": "",
"summaryformat": 1,
"section": 1,
"hiddenbynumsections": 0,
"uservisible": true,
"modules": [
{
"id": 44,
"url": "http://localhost:8077/mod/assign/view.php?id=44",
"name": "Assignment",
"instance": 3,
"contextid": 99,
"visible": 1,
"uservisible": true,
"visibleoncoursepage": 1,
"modicon": "http://localhost:8077/theme/image.php/boost/assign/1613571924/icon",
"modname": "assign",
"modplural": "Assignments",
"indent": 0,
"onclick": "",
"afterlink": null,
"customdata": "\"\"",
"noviewlink": false,
"completion": 1,
"completiondata": {
"state": 0,
"timecompleted": 0,
"overrideby": null,
"valueused": false
}
},
{
"id": 46,
"url": "http://localhost:8077/mod/resource/view.php?id=46",
"name": "test(.txt)",
"instance": 24,
"contextid": 102,
"visible": 1,
"uservisible": true,
"visibleoncoursepage": 1,
"modicon": "http://localhost:8077/theme/image.php/boost/core/1613571924/f/text-24",
"modname": "resource",
"modplural": "Files",
"indent": 0,
"onclick": "",
"afterlink": null,
"customdata": "\"a:1:{s:10:\\\"printintro\\\";i:1;}\"",
"noviewlink": false,
"completion": 1,
"completiondata": {
"state": 0,
"timecompleted": 0,
"overrideby": null,
"valueused": false
},
"contents": [
{
"type": "file",
"filename": "test.txt",
"filepath": "/",
"filesize": 935,
"fileurl": "http://localhost:8077/webservice/pluginfile.php/102/mod_resource/content/1/test.txt?forcedownload=1",
"timecreated": 1621949734,
"timemodified": 1621949744,
"sortorder": 1,
"mimetype": "text/plain",
"isexternalfile": false,
"userid": 2,
"author": "ABC",
"license": "unknown"
}
],
"contentsinfo": {
"filescount": 1,
"filessize": 935,
"lastmodified": 1621949744,
"mimetypes": [
"text/plain"
],
"repositorytype": ""
}
}
]
}
]
I want to get the files from the assignment. Is there a way to achieve this?

How to retrieve Forum/discussion attachments of a course in Moodle LMS?

I have to list all the attachments of a discussion in a course. I don't know how to retrieve all the attachments URLs in a forum/discussion in Moodle LMS.
My code is in c# and usually, I call the Moodle REST API as http://localhost:8077/webservice/rest/server.php?wstoken=11e2d8b7f8e21ca1804e41e9cac5a812&wsfunction=core_course_get_contents&courseid=4&moodlewsrestformat=json and I can get the fileurl for the course files.
Likewise, I would like to retrieve forum/discussion files but I don't see any fileurl or something similar.
I only see the response as below:
[
{
"id": 22,
"name": "General",
"visible": 1,
"summary": "",
"summaryformat": 1,
"section": 0,
"hiddenbynumsections": 0,
"uservisible": true,
"modules": []
},
{
"id": 23,
"name": "Introduction",
"visible": 1,
"summary": "",
"summaryformat": 1,
"section": 1,
"hiddenbynumsections": 0,
"uservisible": true,
"modules": [
{
"id": 46,
"url": "http://localhost:8077/mod/resource/view.php?id=46",
"name": "Everest (.txt)",
"instance": 24,
"contextid": 102,
"visible": 1,
"uservisible": true,
"visibleoncoursepage": 1,
"modicon": "http://localhost:8077/theme/image.php/boost/core/1613571924/f/text-24",
"modname": "resource",
"modplural": "Files",
"indent": 0,
"onclick": "",
"afterlink": null,
"customdata": "\"a:1:{s:10:\\\"printintro\\\";i:1;}\"",
"noviewlink": false,
"completion": 1,
"completiondata": {
"state": 0,
"timecompleted": 0,
"overrideby": null,
"valueused": false
},
"contents": [
{
"type": "file",
"filename": "Everest.txt",
"filepath": "/",
"filesize": 935,
"fileurl": "http://localhost:8077/webservice/pluginfile.php/102/mod_resource/content/1/Everest.txt?forcedownload=1",
"timecreated": 1621949734,
"timemodified": 1621949744,
"sortorder": 1,
"mimetype": "text/plain",
"isexternalfile": false,
"userid": 2,
"author": "DP Bhatt",
"license": "unknown"
}
],
"contentsinfo": {
"filescount": 1,
"filessize": 935,
"lastmodified": 1621949744,
"mimetypes": [
"text/plain"
],
"repositorytype": ""
}
},
{
"id": 47,
"url": "http://localhost:8077/mod/forum/view.php?id=47",
"name": "Forum",
"instance": 5,
"contextid": 112,
"visible": 1,
"uservisible": true,
"visibleoncoursepage": 1,
"modicon": "http://localhost:8077/theme/image.php/boost/forum/1613571924/icon",
"modname": "forum",
"modplural": "Forums",
"indent": 0,
"onclick": "",
"afterlink": null,
"customdata": "\"\"",
"noviewlink": false,
"completion": 1,
"completiondata": {
"state": 0,
"timecompleted": 0,
"overrideby": null,
"valueused": false
}
}
]
}
]
It would be great if someone guides me on the right path. Thank you very much in advance.

Cytoscape Dijkstra Algorithm off?

I'm trying to use Cytoscape to test Dijkstra's algorithm on various graphs. Using the graph below
It's easy to see that the shortest path from A to C would be A -> D -> E -> C.
When running Cytoscape's Djikstra's algorithm though
const dijkstra = cy.elements().dijkstra('#A', function(){
const weight = this.data('weight');
return weight;
}, false);
const pathToC = dijkstra.pathTo( cy.$('#C') );
const distToC = dijkstra.distanceTo( cy.$('#C') );
Cytoscape gives the output
A -> B -> C
which is definitely wrong.
Am I doing something wrong? Or is Cytoscape's algorithm off?
PS Code to generate the graph in Cytoscape is
{
"elements": {
"nodes": [
{
"data": {
"id": "A"
},
"position": {
"x": 187,
"y": 135
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "B"
},
"position": {
"x": 516,
"y": 128
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "C"
},
"position": {
"x": 726,
"y": 302
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "D"
},
"position": {
"x": 186,
"y": 447
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "E"
},
"position": {
"x": 510,
"y": 445
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
}
],
"edges": [
{
"data": {
"id": "BA",
"source": "B",
"target": "A",
"weight": "100"
},
"position": {
"x": 514,
"y": 127
},
"group": "edges",
"removed": false,
"selected": true,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "DA",
"source": "D",
"target": "A",
"weight": "1"
},
"position": {
"x": 187,
"y": 446
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "BD",
"source": "B",
"target": "D",
"weight": "100"
},
"position": {
"x": 516,
"y": 127
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "EB",
"source": "E",
"target": "B",
"weight": "100"
},
"position": {
"x": 500,
"y": 442
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "ED",
"source": "E",
"target": "D",
"weight": "1"
},
"position": {
"x": 501,
"y": 443
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "CE",
"source": "C",
"target": "E",
"weight": "5"
},
"position": {
"x": 727,
"y": 304
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "BC",
"source": "B",
"target": "C",
"weight": "5"
},
"position": {
"x": 521,
"y": 132
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
}
]
},
"style": [
{
"selector": "node",
"style": {
"background-color": "#666",
"label": "data(id)"
}
},
{
"selector": "edge",
"style": {
"width": "3px",
"label": "data(weight)",
"line-color": "#ccc",
"target-arrow-color": "#ccc",
"target-arrow-shape": "triangle"
}
}
],
"zoomingEnabled": true,
"userZoomingEnabled": true,
"zoom": 1,
"minZoom": 1.0e-50,
"maxZoom": 1.0e+50,
"panningEnabled": true,
"userPanningEnabled": true,
"pan": {
"x": 0,
"y": 0
},
"boxSelectionEnabled": true,
"renderer": {
"name": "canvas"
}
}
I'm having the same issue, pretty much same code.
Done some debugging, looks like the dist object is concatenating strings rather than adding integers.
dist: Object
AMS11: "0474483" -> 0, 4, 74, 483 should really be 561
BRU11: Infinity
FRA11: Infinity
GVA11: Infinity
LON11: "0474" -> 0, 4, 74 should really be 78
LON21: 0
LON22: "04" -> 0, 4 should really be 4
LON31: "047415" -> 0, 4, 74, 15 should really be 93
LUX21: Infinity
LUX31: Infinity
MOW11: Infinity
MOW12: Infinity
PAR11: "049693"
PAR21: "0474805"
STO21: Infinity
STO31: Infinity
TYO11: Infinity
TYO12: Infinity
Edit: Answer is to change your weights to integers so use "weight": 1 instead of "weight": "1".

vega horizontal bar charts

The vega documentation/tutorials suggest that setting up a horizontal bar chart is easy, but I can't figure it out for the life of me. How would I go about changing a vertical bar chart, such as http://vega.github.io/vega-editor/index.html?spec=bar, to a horizontal one?
Like this
{
"width": 200,
"height": 210,
"padding": "auto",
"data": [
{
"name": "raw",
"values": [
{"x": "A","y": 28},
{"x": "B","y": 55},
{"x": "C","y": 43},
{"x": "D","y": 91},
{"x": "E","y": 81},
{"x": "F","y": 53},
{"x": "G","y": 19},
{"x": "H","y": 87},
{"x": "I","y": 52}
],
"format": {"parse": {"y": "number"}},
"transform": [{"type": "filter","test": "(d.data.y!==null)"}]
}
],
"scales": [],
"marks": [
{
"_name": "cell",
"type": "group",
"properties": {
"enter": {"width": {"value": 200},"height": {"value": 210}}
},
"scales": [
{
"name": "x",
"type": "linear",
"domain": {"data": "raw","field": "data.y"},
"range": [0,200],
"zero": true,
"reverse": false,
"round": true,
"nice": true
},
{
"name": "y",
"type": "ordinal",
"domain": {"data": "raw","field": "data.x"},
"sort": true,
"range": [0,210],
"bandWidth": 21,
"round": true,
"nice": true,
"points": true,
"padding": 1
}
],
"axes": [
{
"type": "x",
"scale": "x",
"properties": {
"grid": {
"stroke": {"value": "#000000"},
"opacity": {"value": 0.08}
}
},
"layer": "back",
"format": "",
"ticks": 5,
"titleOffset": 38,
"grid": true,
"title": "y"
},
{
"type": "y",
"scale": "y",
"properties": {
"labels": {"text": {"template": "{{data | truncate:25}}"}},
"grid": {
"stroke": {"value": "#000000"},
"opacity": {"value": 0.08}
}
},
"layer": "back",
"titleOffset": 28,
"grid": true,
"title": "x"
}
],
"marks": [
{
"type": "rect",
"from": {"data": "raw"},
"properties": {
"enter": {
"x": {"scale": "x","field": "data.y"},
"x2": {"value": 0},
"yc": {"scale": "y","field": "data.x"},
"height": {"value": 21,"offset": -1},
"fill": {"value": "#4682b4"}
},
"update": {
"x": {"scale": "x","field": "data.y"},
"x2": {"value": 0},
"yc": {"scale": "y","field": "data.x"},
"height": {"value": 21,"offset": -1},
"fill": {"value": "#4682b4"}
}
}
}
],
"legends": []
}
]
}
I generated this chart from
{
"data": {
"values": [
{"x":"A", "y":28}, {"x":"B", "y":55}, {"x":"C", "y":43},
{"x":"D", "y":91}, {"x":"E", "y":81}, {"x":"F", "y":53},
{"x":"G", "y":19}, {"x":"H", "y":87}, {"x":"I", "y":52}
]
},
"marktype": "bar",
"encoding": {
"y": {"type": "O","name": "x"},
"x": {"type": "Q","name": "y"}
}
}
with vega-lite (https://vega.github.io/vega-lite/).