Related
A .NET 6 application Upserts documents to CosmosDB.
I get many debug messages (not all writes)
DocDBTrace Error: 0 : DocumentClientException with status code 449, message: Message: {"Errors":["Conflicting request to resource has been attempted. Retry to avoid conflicts."]}
the ids of the documents are Guid instances and there are no unique keys in the container (so no conflicts).
What could it be?
EDIT
partitionKey = id
//F#
let write database container items =
let container = client.GetContainer(database, container)
items
|> Seq.map (fun item -> container.UpsertItemAsync(item))
|> Seq.toArray
|> Task.WhenAll
Data sample
{
"RESPONSE": [
{
"IntradayTickResponse": {
"CorrelationID": "ESM2 Index:intraday",
"TimeReceived": "2022-05-05T01:19:38.338794Z",
"tickData": {
"eidData": null,
"tickData": [
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 7,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.5,
"size": 2,
"conditionCodes": "TSUM"
},
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 19,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.75,
"size": 2,
"conditionCodes": "TSUM"
},
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 19,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.75,
"size": 1,
"conditionCodes": "TSUM"
},
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 19,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.75,
"size": 1,
"conditionCodes": "TSUM"
},
{
"time": {
"DayOfMonth": 5,
"Hour": 0,
"MicroSecond": 0,
"MilliSecond": 0,
"Minute": 37,
"Month": 5,
"NanoSecond": 0,
"Parts": 2046,
"PicoSecond": 0,
"Second": 19,
"TimezoneOffsetMinutes": 0,
"Year": 2022
},
"type": "TRADE",
"value": 4292.75,
"size": 1,
"conditionCodes": "TSUM"
},
...
"id": "87fdc18a-61f2-4c43-a7a8-2904b14e6596",
"_rid": "maszAOGSZkYwAgAAAAAAAA==",
"_self": "dbs/maszAA==/colls/maszAOGSZkY=/docs/maszAOGSZkYwAgAAAAAAAA==/",
"_etag": "\"00000000-0000-0000-601e-3057eca901d8\"",
"_attachments": "attachments/",
"_ts": 1651713578
}
I am using the BoxPacking package in R from here
Although I have manipulated it in many ways, the base is that I cannot export the solution to txt or preferably csv. I've tried converting to data frame or writing lines for txt as suggested here, but keep getting errors:
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class "structure("Container", package = "BoxPacking")" to a data.frame
Is anyone familiar enough with this package to assist please?
Thanks
CSV seems like a bad choice for this since it's a nested structure. JSON wld be far more appropriate.
First, define some json serializers for the custom objects:
library(jsonlite)
setMethod(jsonlite:::asJSON, "Box", function(x, ...) {
jsonlite:::asJSON(
list(
Box =
list(
origin = x#origin,
length = unbox(x#length),
height = unbox(x#height),
width = unbox(x#width)
)
),
...
)
})
setMethod(jsonlite:::asJSON, "EMS", function(x, ...) {
jsonlite:::asJSON(
list(
EMS = list(
origin = x#origin,
length = unbox(x#length),
height = unbox(x#height),
width = unbox(x#width)
)
),
...
)
})
setMethod(jsonlite:::asJSON, "Container", function(x, ...) {
jsonlite:::asJSON(
list(
Container =
list(
origin = x#origin,
length = unbox(x#length),
height = unbox(x#height),
width = unbox(x#width),
ems = x#ems
)
),
...
)
})
then, just call jsonlite::toJSON() on the object:
[
[
{
"Container": {
"origin": [0, 0, 0],
"length": 2,
"height": 2,
"width": 2,
"ems": [
{
"EMS": {
"origin": [0, 0, 0],
"length": 2,
"height": 2,
"width": 2
}
}
]
}
}
],
[
{
"Container": {
"origin": [0, 0, 0],
"length": 2,
"height": 2,
"width": 2,
"ems": [
{
"EMS": {
"origin": [0, 0, 0],
"length": 2,
"height": 2,
"width": 2
}
}
]
}
}
],
[
{
"Container": {
"origin": [0, 0, 0],
"length": 2,
"height": 2,
"width": 2,
"ems": [
{
"EMS": {
"origin": [0, 0, 0],
"length": 2,
"height": 2,
"width": 2
}
}
]
}
}
],
[
{
"Container": {
"origin": [0, 0, 0],
"length": 2,
"height": 2,
"width": 2,
"ems": [
{
"EMS": {
"origin": [0, 1.9, 0],
"length": 2,
"height": 0.1,
"width": 2
}
},
{
"EMS": {
"origin": [0, 0, 1.9],
"length": 2,
"height": 2,
"width": 0.1
}
},
{
"EMS": {
"origin": [1.4, 0.9, 0],
"length": 0.6,
"height": 1.1,
"width": 0.4
}
},
{
"EMS": {
"origin": [0.4, 0.9, 0.4],
"length": 0.1,
"height": 0.5,
"width": 1.6
}
},
{
"EMS": {
"origin": [0, 1.8, 0],
"length": 0.4,
"height": 0.2,
"width": 0.4
}
},
{
"EMS": {
"origin": [0, 1.4, 1.5],
"length": 2,
"height": 0.6,
"width": 0.5
}
},
{
"EMS": {
"origin": [0, 1, 1.4],
"length": 0.4,
"height": 1,
"width": 0.6
}
},
{
"EMS": {
"origin": [0, 1, 1.5],
"length": 0.5,
"height": 1,
"width": 0.5
}
},
{
"EMS": {
"origin": [0, 1, 1.4],
"length": 0.5,
"height": 0.4,
"width": 0.6
}
},
{
"EMS": {
"origin": [0.9, 1.4, 0],
"length": 1.1,
"height": 0.6,
"width": 0.5
}
},
{
"EMS": {
"origin": [1.4, 1.4, 0],
"length": 0.6,
"height": 0.6,
"width": 2
}
},
{
"EMS": {
"origin": [1.5, 1.3, 0],
"length": 0.5,
"height": 0.7,
"width": 2
}
},
{
"EMS": {
"origin": [1, 1.3, 1.5],
"length": 1,
"height": 0.7,
"width": 0.5
}
},
{
"EMS": {
"origin": [1, 0, 1.4],
"length": 1,
"height": 0.9,
"width": 0.6
}
},
{
"EMS": {
"origin": [1.4, 1.3, 0.9],
"length": 0.6,
"height": 0.7,
"width": 1.1
}
},
{
"EMS": {
"origin": [1, 1.3, 0.9],
"length": 1,
"height": 0.1,
"width": 1.1
}
},
{
"EMS": {
"origin": [1.4, 0, 0.8],
"length": 0.6,
"height": 0.4,
"width": 0.1
}
},
{
"EMS": {
"origin": [1.5, 0, 0],
"length": 0.5,
"height": 2,
"width": 0.4
}
},
{
"EMS": {
"origin": [1.8, 0, 0],
"length": 0.2,
"height": 2,
"width": 0.9
}
},
{
"EMS": {
"origin": [1.5, 0, 0.8],
"length": 0.5,
"height": 2,
"width": 0.1
}
},
{
"EMS": {
"origin": [1.5, 0.4, 0],
"length": 0.5,
"height": 1.6,
"width": 0.9
}
},
{
"EMS": {
"origin": [1.8, 0, 0],
"length": 0.2,
"height": 0.5,
"width": 2
}
},
{
"EMS": {
"origin": [1.5, 0, 0.8],
"length": 0.5,
"height": 0.5,
"width": 1.2
}
},
{
"EMS": {
"origin": [1.5, 0.4, 0],
"length": 0.5,
"height": 0.1,
"width": 2
}
},
{
"EMS": {
"origin": [0.8, 0, 1.4],
"length": 1.2,
"height": 0.4,
"width": 0.6
}
},
{
"EMS": {
"origin": [0.4, 0, 1.8],
"length": 1.6,
"height": 0.4,
"width": 0.2
}
},
{
"EMS": {
"origin": [0.4, 0, 1.8],
"length": 0.1,
"height": 2,
"width": 0.2
}
},
{
"EMS": {
"origin": [0.4, 0.4, 1.5],
"length": 0.1,
"height": 1.6,
"width": 0.5
}
},
{
"EMS": {
"origin": [0.4, 0.4, 1.4],
"length": 0.1,
"height": 1,
"width": 0.6
}
}
]
}
},
{
"Box": {
"origin": [0, 0, 0],
"length": 1,
"height": 1,
"width": 0.4
}
},
{
"Box": {
"origin": [0, 0, 0.4],
"length": 1,
"height": 0.4,
"width": 1
}
},
{
"Box": {
"origin": [0, 0.4, 0.4],
"length": 0.5,
"height": 0.5,
"width": 1
}
},
{
"Box": {
"origin": [0.5, 0.4, 0.4],
"length": 1,
"height": 1,
"width": 0.5
}
},
{
"Box": {
"origin": [0, 0.9, 0.4],
"length": 0.4,
"height": 1,
"width": 1
}
},
{
"Box": {
"origin": [0.5, 0.4, 0.9],
"length": 0.5,
"height": 1,
"width": 1
}
},
{
"Box": {
"origin": [1, 0, 0],
"length": 0.5,
"height": 0.4,
"width": 0.4
}
},
{
"Box": {
"origin": [1, 0, 0.9],
"length": 0.5,
"height": 0.5,
"width": 0.5
}
},
{
"Box": {
"origin": [0, 1, 0],
"length": 1,
"height": 0.4,
"width": 0.4
}
},
{
"Box": {
"origin": [1, 0.4, 0],
"length": 0.5,
"height": 0.5,
"width": 0.4
}
},
{
"Box": {
"origin": [1, 0, 0.4],
"length": 0.4,
"height": 0.4,
"width": 0.5
}
},
{
"Box": {
"origin": [0, 0, 1.4],
"length": 0.4,
"height": 1,
"width": 0.5
}
},
{
"Box": {
"origin": [1, 0.9, 0],
"length": 0.4,
"height": 0.5,
"width": 0.4
}
},
{
"Box": {
"origin": [1, 0.5, 0.9],
"length": 1,
"height": 0.4,
"width": 0.5
}
},
{
"Box": {
"origin": [0, 1.4, 0],
"length": 0.4,
"height": 0.4,
"width": 0.4
}
},
{
"Box": {
"origin": [0.4, 1.4, 0],
"length": 0.5,
"height": 0.5,
"width": 0.5
}
},
{
"Box": {
"origin": [0.4, 1.4, 0.5],
"length": 1,
"height": 0.5,
"width": 1
}
},
{
"Box": {
"origin": [1, 0.9, 0.9],
"length": 1,
"height": 0.4,
"width": 1
}
},
{
"Box": {
"origin": [1.4, 0, 0.4],
"length": 0.4,
"height": 0.4,
"width": 0.4
}
},
{
"Box": {
"origin": [0.4, 0, 1.4],
"length": 0.4,
"height": 0.4,
"width": 0.4
}
}
]
]
How do I prevent the first and last bars from being cut off (showing half)?
I need to show the short month names on the x-axis. I've tried playing around with various min/max settings, but I can't seem to get it right.
var graphData = {
dates: [
'2016-06-01',
'2016-07-01',
'2016-08-01',
'2016-09-01',
'2016-10-01',
'2016-11-01',
'2016-12-01',
'2017-01-01',
'2017-02-01',
'2017-03-01',
'2017-04-01',
'2017-05-01'
],
wins: [23, 5, 13, 24, 8, 11, 23, 5, 13, 24, 8, 11],
draws: [2, 1, 2, 0, 2, 2, 3, 1, 2, 4, 0, 1],
losses: [3, 1, 2, 10, 8, 8, 3, 1, 2, 10, 8, 8],
winRates: [50, 40, 72, 30, 46, 80, 50, 40, 72, 30, 46, 80]
};
var winsMax = Math.max.apply(Math, graphData.wins);
var lossesMax = Math.max.apply(Math, graphData.losses);
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: "bar",
data: {
labels: graphData.dates.map((date) => moment(date)),
datasets: [
{
type: "bar",
backgroundColor: "green",
hoverBackgroundColor: "green",
data: graphData.wins,
yAxisID: "winsAndLosses"
},
{
type: "bar",
backgroundColor: "red",
hoverBackgroundColor: "red",
data: graphData.losses.map((i) => -i),
yAxisID: "winsAndLosses"
},
{
type: "line",
data: graphData.winRates,
fill: true,
backgroundColor: "gray",
pointRadius: 0,
pointHoverRadius: 0,
yAxisID: "winRate"
}
]
},
options: {
legend: {
display: false
},
scales: {
xAxes: [{
type: "time",
time: {
unit: "month",
displayFormats: {
month: "MMM"
}
},
stacked: true,
gridLines: {
display: false
},
ticks: {
callback: (label) => label.toUpperCase(),
fontSize: 10
}
}],
yAxes: [
{
id: "winsAndLosses",
stacked: true,
ticks: {
min: (lossesMax + 10) * -1,
max: winsMax + 10,
callback: (label) => Math.abs(label) // TODO: Localization (number formatting).
},
display: false
},
{
id: "winRate",
ticks: {
min: 0,
max: 100,
stepSize: 10,
callback: (label) => label + "%", // TODO: Localization (number formatting).
fontSize: 10
}
}
]
}
}
});
.myChartDiv {
max-width: 800px;
max-height: 400px;
}
<script src="https://npmcdn.com/chart.js#latest/dist/Chart.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<html>
<body>
<div class="myChartDiv">
<canvas id="myChart" width="800" height="400"></canvas>
</div>
</body>
</html>
There's a setting called offset which seems to work for me:
xAxes: [{
offset: true
}]
var graphData = {
dates: [
'2016-06-01',
'2016-07-01',
'2016-08-01',
'2016-09-01',
'2016-10-01',
'2016-11-01',
'2016-12-01',
'2017-01-01',
'2017-02-01',
'2017-03-01',
'2017-04-01',
'2017-05-01'
],
wins: [23, 5, 13, 24, 8, 11, 23, 5, 13, 24, 8, 11],
draws: [2, 1, 2, 0, 2, 2, 3, 1, 2, 4, 0, 1],
losses: [3, 1, 2, 10, 8, 8, 3, 1, 2, 10, 8, 8],
winRates: [50, 40, 72, 30, 46, 80, 50, 40, 72, 30, 46, 80]
};
var winsMax = Math.max.apply(Math, graphData.wins);
var lossesMax = Math.max.apply(Math, graphData.losses);
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: "bar",
data: {
labels: graphData.dates.map((date) => moment(date)),
datasets: [
{
type: "bar",
backgroundColor: "green",
hoverBackgroundColor: "green",
data: graphData.wins,
yAxisID: "winsAndLosses"
},
{
type: "bar",
backgroundColor: "red",
hoverBackgroundColor: "red",
data: graphData.losses.map((i) => -i),
yAxisID: "winsAndLosses"
},
{
type: "line",
data: graphData.winRates,
fill: true,
backgroundColor: "gray",
pointRadius: 0,
pointHoverRadius: 0,
yAxisID: "winRate"
}
]
},
options: {
legend: {
display: false
},
scales: {
xAxes: [{
type: "time",
time: {
unit: "month",
displayFormats: {
month: "MMM"
}
},
stacked: true,
gridLines: {
display: false
},
ticks: {
callback: (label) => label.toUpperCase(),
fontSize: 10
},
offset:true
}],
yAxes: [
{
id: "winsAndLosses",
stacked: true,
ticks: {
min: (lossesMax + 10) * -1,
max: winsMax + 10,
callback: (label) => Math.abs(label) // TODO: Localization (number formatting).
},
display: false
},
{
id: "winRate",
ticks: {
min: 0,
max: 100,
stepSize: 10,
callback: (label) => label + "%", // TODO: Localization (number formatting).
fontSize: 10
}
}
]
}
}
});
.myChartDiv {
max-width: 800px;
max-height: 400px;
}
<script src="https://npmcdn.com/chart.js#latest/dist/Chart.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<html>
<body>
<div class="myChartDiv">
<canvas id="myChart" width="800" height="400"></canvas>
</div>
</body>
</html>
I'm trying to create chart in Highcharts with four arearanges and one line. I'm doing my best to get something like on image:
arearanges
I'v managed to do something like this:
$(function () {
var rangesHI = [
[1246406400000, 90, 75],
[1248998400000, 90, 75]
],
rangesME = [
[1246406400000, 75, 60],
[1248998400000, 75, 60]
],
rangesNO = [
[1246406400000, 60, 35],
[1248998400000, 60, 35]
],
rangesLO = [
[1246406400000, 35, 15],
[1248998400000, 35, 15]
],
averages = [
[1246406400000, 31.5],
[1246492800000, 32.1],
[1246579200000, 33],
[1246665600000, 33.8],
[1246752000000, 31.4],
[1246838400000, 31.3],
[1246924800000, 38.3],
[1247011200000, 35.4],
[1247097600000, 36.4],
[1247184000000, 47.7],
[1247270400000, 47.5],
[1247356800000, 37.6],
[1247443200000, 47.7],
[1247529600000, 46.8],
[1247616000000, 47.7],
[1247702400000, 46.3],
[1247788800000, 47.8],
[1247875200000, 48.1],
[1247961600000, 57.2],
[1248048000000, 54.4],
[1248134400000, 53.7],
[1248220800000, 55.7],
[1248307200000, 54.6],
[1248393600000, 55.3],
[1248480000000, 45.3],
[1248566400000, 55.8],
[1248652800000, 65.2],
[1248739200000, 74.8],
[1248825600000, 44.4],
[1248912000000, 55],
[1248998400000, 43.6]
];
$('#container').highcharts({
title: {
text: null
},
xAxis: {
type: 'datetime'
},
yAxis: {
max:90,
min:20,
title: {
text: null
}
},
series: [{
name: 'RH',
data: averages,
zIndex: 1
}, {
data: rangesHI,
type: 'arearange',
lineWidth: 0,
fillColor: {
linearGradient: [0, 0, 0, 300],
stops: [
[0, 'rgba(255,0,0, 0.2)'],
[1, 'rgba(255,0,0, 1)']
]
},
zIndex: 0
}, {
data: rangesME,
type: 'arearange',
lineWidth: 0,
fillColor: {
linearGradient: [300, 0, 300, 400],
stops: [
[0, 'rgba(237,230,126, 0.2)'],
[1, 'rgba(237,230,126, 1)']
]
},
zIndex: 0
}, {
data: rangesNO,
type: 'arearange',
lineWidth: 0,
fillColor: {
linearGradient: [500, 0, 500, 600],
stops: [
[0, 'rgba(104,217,91, 0.2)'],
[1, 'rgba(104,217,91, 0.7)']
]
},
zIndex: 0
}, {
data: rangesLO,
type: 'arearange',
lineWidth: 0,
fillColor: {
linearGradient: [0, 0, 0, 220],
stops: [
[0, 'rgba(91,187,217, 0.2)'],
[1, 'rgba(91,187,217, 0.7)']
]
},
zIndex: 0
}]
}, function (chart) {
chart.renderer.text('EKSTREMALNA', 80, 95).css({
fontSize: '16pt',
color: 'rgba(255,0,0, 1)'
}).add();
chart.renderer.text('WYSOKA', 80, 145).css({
fontSize: '16pt',
color: 'rgba(237,230,126, 1)'
}).add();
chart.renderer.text('KOMFORTOWA', 80, 225).css({
fontSize: '16pt',
color: 'rgba(104,217,91, 01)'
}).add();
chart.renderer.text('NISKA', 80, 305).css({
fontSize: '16pt',
color: 'rgba(91,187,217, 1)'
}).add();
});
http://jsfiddle.net/qazopap4/1/ but this is far from what I'v expected.
I can't make linear gradient for each arearange separately.
You can use plotBands which allows you to apply gradients.
yAxis: {
plotBands: [{
from: 60,
to: 90,
color: {
linearGradient: [0, 0, 0, 300],
stops: [
[0, 'rgba(255,0,0, 0.2)'],
[1, 'rgba(255,0,0, 1)']
]
}
}],
max: 90,
min: 20,
title: {
text: null
}
},
Example: http://jsfiddle.net/pag5qgsm
I am using AmChartXY to draw graph areas, here is the fiddle:
https://jsfiddle.net/ap60fhsu/1/
var chart = AmCharts.makeChart("chartdiv", {
"type": "xy",
"autoMarginOffset": 20,
"dataProvider": [{
"ax": 0,
"ay": 0,
"bx": 0,
"by": 0,
}, {
"ax": 8,
"ay": 1,
"bx": 12,
"by": -2,
},
{
"ax": 32,
"ay": 9,
"bx": 35,
"by": -1,
},
{
"ax": 45,
"ay": 6,
"bx": 45,
"by": -2,
},
{
"ax": 60,
"ay": 2,
"bx": 60,
"by": -2,
},
{
"ax": 70,
"ay": 0,
"bx": 70,
"by": 0,
},
{
"ax": 75,
"ay": 0,
"bx": 72,
"by": 0,
},
{
"ax": 85,
"ay": 6,
"bx": 80,
"by": -1,
},
{
"ax": 90,
"ay": 0,
"bx": 90,
"by": 0,
}],
"valueAxes": [ {
"position": "bottom",
"axisAlpha": 0,
"dashLength": 1,
"id": "x",
"title": "X Axis"
}, {
"axisAlpha": 0,
"dashLength": 1,
"position": "left",
"id": "y",
"title": "Y Axis"
}],
"plotAreaBorderAlpha": 1,
"startDuration": 1,
"graphs": [ {
"balloonText": "x:[[x]] y:[[y]]",
"fillAlphas": 0.3,
"fillToAxis": "x",
"lineAlpha": 1,
"xField": "ax",
"yField": "ay",
"lineColor": "#FF6600"
}, {
"balloonText": "x:[[x]] y:[[y]]",
"lineAlpha": 1,
"fillToAxis": "x",
"fillAlphas": 0.3,
"xField": "bx",
"yField": "by",
"lineColor": "#FCD202"
}],
"marginLeft": 64,
"marginBottom": 60,
"chartScrollbar": {},
"chartCursor": {},
"export": {
"enabled": true,
"position": "bottom-right"
}
});
As you see I have negative values for Y axis, this makes the X axis fall down from Y=0 to Y=-4 and when I use fillToAxis: x, expecting that the graph fill areas will be areas bounded with graphs and X axis corresponding to the value Y=0, I get another result. How can I move the X axis to the Y=0, or at least get the fill area result as I expect?
Thanks in advance