Survey design for multilevel analysis - cluster-analysis

I am new in using R, and I need to run a multilevel analysis (two-phase design on two levels) using Cox frailty survival model on a survey data (Nigeria Demographic and Health Survey Data).
My problem is how to write the design weight using the two weights needed and apply them to the analysis.
I have identified the needed variables for the survey design, which are :
psu/cluster= v021
individual-level weight= wt1_1
cluster-level weigh= wt2_1
strata/stratum= v022
Please can someone help me with the survey design (svydesign) code and how to include it and the weights in a model.
I understand I have to use svycoxph in the model. Please how do I include survey design and account for the 2 weights (individual-level and cluster-level weights) in the gamma frailty model below?
Frailty1 <- coxph (Surv(study_time, died) ~ factor(v024) + factor(mat_edu) + v025 + frailty(v021,distribution="gamma"), data=rcom2018)
Really looking forward to your help as my project is hanging on this.
Many thanks.
library(survival)
#> Warning: package 'survival' was built under R version 4.0.5
library(frailtypack)
#> Warning: package 'frailtypack' was built under R version 4.0.5
#> Loading required package: boot
#>
#> Attaching package: 'boot'
#> The following object is masked from 'package:survival':
#>
#> aml
#> Loading required package: MASS
#> Loading required package: survC1
#> Warning: package 'survC1' was built under R version 4.0.5
#> Loading required package: doBy
#> Warning: package 'doBy' was built under R version 4.0.5
#>
#> Attaching package: 'frailtypack'
#> The following object is masked from 'package:survival':
#>
#> cluster
rcom1 <- data.frame(
data.frame(
pid = c(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100
),
study_time = c(
13, 9, 17, 31, 39, 22, 24, 0, 23, 12, 9, 35,
18, 20, 60, 18, 5, 46, 26, 54, 37, 51, 31, 55, 27, 15, 39, 6,
29, 0, 9, 40, 23, 12, 35, 56, 14, 40, 57, 42, 5, 42, 39, 39,
54, 19, 52, 42, 7, 28, 53, 5, 28, 13, 37, 0, 23, 33, 27, 36, 20,
24, 58, 34, 12, 44, 3, 34, 14, 5, 10, 40, 12, 36, 19, 58, 17,
40, 39, 58, 53, 53, 1, 50, 2, 28, 24, 13, 13, 50, 46, 46, 19, 6,
32, 59, 9, 30, 30, 43
),
died = c(
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0
),
v021 = c(
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6
),
v022 = c(
"1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2"
),
v012 = c(
40, 37, 27, 27, 24, 32, 35, 35, 34, 20, 28,
28, 26, 24, 24, 25, 26, 26, 26, 26, 28, 27, 25, 25, 27, 26, 26,
21, 21, 31, 36, 36, 27, 23, 32, 32, 33, 33, 33, 28, 25, 37,
33, 34, 33, 28, 28, 29, 33, 33, 33, 39, 38, 38, 38, 38, 24, 27,
35, 40, 22, 38, 38, 21, 30, 30, 30, 39, 43, 18, 23, 23, 25, 25,
30, 45, 26, 26, 35, 35, 35, 35, 32, 32, 40, 25, 27, 30, 30, 30,
28, 28, 18, 27, 30, 30, 27, 21, 21, 30
),
wt2_1 = c(
401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031,
401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
631.818176269531, 631.818176269531, 631.818176269531,
631.818176269531, 631.818176269531, 631.818176269531, 631.818176269531,
631.818176269531, 631.818176269531, 631.818176269531
),
wt1_1 = c(
2.5074667930603, 2.5074667930603,
2.5074667930603, 2.5074667930603, 2.5074667930603, 2.5074667930603,
2.5074667930603, 2.5074667930603, 2.5074667930603, 2.5074667930603,
2.5074667930603, 2.5074667930603, 2.5074667930603,
2.5074667930603, 2.5074667930603, 5.1194109916687, 5.1194109916687,
5.1194109916687, 5.1194109916687, 5.1194109916687, 5.1194109916687,
5.1194109916687, 5.1194109916687, 5.1194109916687,
5.1194109916687, 5.1194109916687, 5.1194109916687, 5.1194109916687,
5.1194109916687, 5.1194109916687, 5.1194109916687, 5.1194109916687,
5.1194109916687, 5.1194109916687, 2.40910983085632,
2.40910983085632, 2.40910983085632, 2.40910983085632, 2.40910983085632,
2.40910983085632, 2.40910983085632, 2.40910983085632,
2.40910983085632, 2.40910983085632, 2.40910983085632, 2.40910983085632,
2.40910983085632, 2.40910983085632, 1.06203985214233,
1.06203985214233, 1.06203985214233, 1.06203985214233, 1.06203985214233,
1.06203985214233, 1.06203985214233, 1.06203985214233,
1.06203985214233, 1.06203985214233, 1.06203985214233, 1.06203985214233,
1.06203985214233, 1.06203985214233, 1.06203985214233,
1.06203985214233, 1.06203985214233, 1.06203985214233, 1.06203985214233,
2.80098295211792, 2.80098295211792, 2.80098295211792,
2.80098295211792, 2.80098295211792, 2.80098295211792, 2.80098295211792,
2.80098295211792, 2.80098295211792, 2.80098295211792,
2.80098295211792, 2.80098295211792, 2.80098295211792, 2.80098295211792,
2.80098295211792, 2.80098295211792, 2.80098295211792,
2.80098295211792, 2.80098295211792, 2.80098295211792, 2.80098295211792,
2.80098295211792, 2.80098295211792, 1.24210178852081,
1.24210178852081, 1.24210178852081, 1.24210178852081, 1.24210178852081,
1.24210178852081, 1.24210178852081, 1.24210178852081,
1.24210178852081, 1.24210178852081
),
v024 = c(
"1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1"
),
v025 = c(
"1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2"
),
mat_edu = c(
"5", "5", "5", "4", "4", "5", "4", "4", "4",
"4", "4", "4", "5", "5", "5", "5", "5", "5", "4", "4", "5",
"4", "4", "4", "5", "3", "3", "4", "4", "5", "5", "5", "5", "4",
"2", "2", "0", "0", "0", "5", "5", "0", "1", "5", "5", "3",
"3", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "4", "5",
"5", "4", "5", "5", "3", "4", "4", "5", "3", "1", "3", "3", "3",
"1", "3", "2", "1", "3", "3", "4", "4", "0", "0", "2", "2",
"1", "0", "4", "4", "4", "4", "0", "0", "3", "4", "2", "2", "3",
"3", "3", "0"
)
)
)
Created on 2022-02-01 by the reprex package (v2.0.1)

Related

2 level mongo $group - aggregation

Been trying to read the docs and examples to try and figure this out but it's proving difficult (especially as a noobie with little idea behind what all the different terms mean).
We have a couple of collections and are trying to quantify/chart some data from it. We have managed to massage the data via aggregation stages so that the documents look like this:
[
{
_id: 1,
sender: 'foo',
messages: [
{_id: 10, text: 'hello', recipientCount: 3, sentAt: '2019-10'},
{_id: 11, text: 'hello', recipientCount: 3, sentAt: '2019-10'},
{_id: 12, text: 'hello', recipientCount: 3, sentAt: '2019-10'},
]
},
{
_id: 2,
sender: 'bar',
messages: [
{_id: 13, text: 'hello', recipientCount: 3, sentAt: '2018-10'},
{_id: 14, text: 'hello', recipientCount: 3, sentAt: '2018-10'},
{_id: 15, text: 'hello', recipientCount: 3, sentAt: '2018-10'},
]
},
{
_id: 3,
sender: 'foo',
messages: [
{_id: 16, text: 'hello', recipientCount: 13, sentAt: '2020-10'},
{_id: 17, text: 'hello', recipientCount: 13, sentAt: '2020-10'},
{_id: 18, text: 'hello', recipientCount: 13, sentAt: '2020-10'},
]
},
{
_id: 4,
sender: 'foo',
messages: [
{_id: 19, text: 'hello', recipientCount: 3, sentAt: '2021-10'},
{_id: 110, text: 'hello', recipientCount: 3, sentAt: '2021-10'},
{_id: 111, text: 'hello', recipientCount: 3, sentAt: '2021-10'},
]
},
{
_id: 5,
sender: 'bar',
messages: [
{_id: 112, text: 'hello', recipientCount: 1, sentAt: '2021-4'},
{_id: 113, text: 'hello', recipientCount: 1, sentAt: '2021-4'},
{_id: 114, text: 'hello', recipientCount: 1, sentAt: '2021-4'},
]
},
{
_id: 6,
sender: 'foo',
messages: [
{_id: 115, text: 'hello', recipientCount: 4, sentAt: '2020-8'},
{_id: 116, text: 'hello', recipientCount: 4, sentAt: '2020-8'},
{_id: 117, text: 'hello', recipientCount: 4, sentAt: '2020-8'},
]
},
{
_id: 7,
sender: 'cap',
messages: [
{_id: 118, text: 'hello', recipientCount: 7, sentAt: '2018-6'},
{_id: 119, text: 'hello', recipientCount: 7, sentAt: '2018-6'},
{_id: 120, text: 'hello', recipientCount: 7, sentAt: '2018-6'},
]
},
{
_id: 8,
sender: 'cap',
messages: [
{_id: 121, text: 'hello', recipientCount: 12, sentAt: '2019-11'},
{_id: 122, text: 'hello', recipientCount: 12, sentAt: '2019-11'},
{_id: 123, text: 'hello', recipientCount: 12, sentAt: '2019-11'},
]
},
{
_id: 9,
sender: 'foo',
messages: [
{_id: 124, text: 'hello', recipientCount: 2, sentAt: '2020-12'},
{_id: 125, text: 'hello', recipientCount: 2, sentAt: '2020-12'},
{_id: 126, text: 'hello', recipientCount: 2, sentAt: '2020-12'},
]
},
{
_id: 10,
sender: 'foo',
messages: [
{_id: 127, text: 'hello', recipientCount: 1, sentAt: '2021-1'},
{_id: 128, text: 'hello', recipientCount: 1, sentAt: '2021-1'},
{_id: 129, text: 'hello', recipientCount: 1, sentAt: '2021-1'},
]
},
{
_id: 11,
sender: 'cap',
messages: [
{_id: 130, text: 'hello', recipientCount: 2, sentAt: '2019-2'},
{_id: 131, text: 'hello', recipientCount: 2, sentAt: '2019-2'},
{_id: 132, text: 'hello', recipientCount: 2, sentAt: '2019-2'},
]
},
]
We want output that will allow us to create a table showing the total recipientCount grouped by sender and sentAt. I.e. - Something along the lines of:
2018-1 2018-2 2018-3 2018-4
foo 3 4 31 18
bar 7 24 11 17
cap 19 6 23 75
What would be the next (and final?) stage of this aggregation pipeline?
Thanks in advance!
Just unwind the messages array and group on sender and sentAt.Like this:
db.collection.aggregate([
{
"$unwind": "$messages"
},
{
"$group": {
"_id": {
sender: "$sender",
sentAt: "$messages.sentAt"
},
"count": {
"$sum": "$messages.recipientCount"
}
}
},
{
"$project": {
"sender": "$_id.sender",
"sentAt": "$_id.sentAt",
"count": 1,
"_id": 0
}
}
])
Playground link.

Flutter How to display JSON response on Listview

I want to display JSON data on Listview when I do button click, I can print valid JSON data on console so I want a way to show it on a listview, I am still a beginner in Flutter, your help will be appreaciated.
My model class
class Vehicle {
int? id;
int? sourceId;
int? serviceId;
int? categoryId;
String? category;
String? description;
dynamic value;
int? serviceResponsePropertyId;
int? mappingId;
bool? isVisible;
int? packageRequestId;
int? sortOrder;
Vehicle(
{required this.id,
required this.sourceId,
required this.serviceId,
required this.categoryId,
required this.category,
required this.description,
required this.value,
required this.serviceResponsePropertyId,
required this.mappingId,
required this.isVisible,
required this.packageRequestId,
required this.sortOrder});
Vehicle.fromJson(Map<String, dynamic> json) {
id = json['Id'];
sourceId = json['SourceId'];
serviceId = json['ServiceId'];
categoryId = json['CategoryId'];
category = json['Category'];
description = json['Description'];
value = json['Value'];
serviceResponsePropertyId = json['ServiceResponsePropertyId'];
mappingId = json['MappingId'];
isVisible = json['IsVisible'];
packageRequestId = json['PackageRequestId'];
sortOrder = json['SortOrder'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = {};
data['Id'] = id;
data['SourceId'] = sourceId;
data['ServiceId'] = serviceId;
data['CategoryId'] = categoryId;
data['Category'] = category;
data['Description'] = description;
data['Value'] = value;
data['ServiceResponsePropertyId'] = serviceResponsePropertyId;
data['MappingId'] = mappingId;
data['IsVisible'] = isVisible;
data['PackageRequestId'] = packageRequestId;
data['SortOrder'] = sortOrder;
return data;
}
}
JSON response
[
{
"Id": 0,
"SourceId": 0,
"ServiceId": 11,
"CategoryId": 5,
"Category": "Valuation",
"Description": "AdjustedValues",
"Value": [],
"ServiceResponsePropertyId": 474,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 11,
"CategoryId": 1,
"Category": "General",
"Description": "ServiceStatus",
"Value": {
"StatusCode": 1,
"StatusDescription": "Ok",
"StatusDetail": "",
"RestServiceStatus": null,
"ServiceResource": null
},
"ServiceResponsePropertyId": 475,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "CarId",
"Value": 120354,
"ServiceResponsePropertyId": 100,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Year",
"Value": 2017,
"ServiceResponsePropertyId": 103,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 6
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Full Model Description",
"Value": "2017 AUDI A3 Sedan 1.0T FSI S tronic [2016-2017]",
"ServiceResponsePropertyId": 104,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Model",
"Value": "A3 Sedan 1.0T FSI S tronic [2016-2017]",
"ServiceResponsePropertyId": 105,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 5
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "ImageUrl",
"Value": "https://cdn.lightstoneauto.co.za/PHOTOS/AUDI/120354_1_Z7.jpg",
"ServiceResponsePropertyId": 107,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Make",
"Value": "AUDI",
"ServiceResponsePropertyId": 110,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 3
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Type",
"Value": "AUDI A3 Sedan",
"ServiceResponsePropertyId": 111,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 4
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "ServiceStatus",
"Value": {
"StatusCode": 1,
"StatusDescription": "Ok",
"StatusDetail": "",
"RestServiceStatus": null,
"ServiceResource": null
},
"ServiceResponsePropertyId": 125,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 7,
"CategoryId": 1,
"Category": "General",
"Description": "ServiceStatus",
"Value": {
"StatusCode": 1,
"StatusDescription": "Ok",
"StatusDetail": "",
"RestServiceStatus": null,
"ServiceResource": null
},
"ServiceResponsePropertyId": 126,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13870410,
"SortOrder": 9999
},
{
"CarId": 0,
"SpecCategory": "General",
"Id": -1,
"SourceId": -1,
"ServiceId": 7,
"CategoryId": 1,
"Category": "General",
"Description": "Body shape",
"Value": "Sedan",
"ServiceResponsePropertyId": 320,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 9999
},
{
"CarId": 0,
"SpecCategory": "General",
"Id": -6,
"SourceId": -6,
"ServiceId": 7,
"CategoryId": 1,
"Category": "General",
"Description": "Drive type",
"Value": "4x2",
"ServiceResponsePropertyId": 154,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 9999
},
{
"CarId": 0,
"SpecCategory": "General",
"Id": -7,
"SourceId": -7,
"ServiceId": 7,
"CategoryId": 1,
"Category": "General",
"Description": "Fuel type",
"Value": "Petrol",
"ServiceResponsePropertyId": 153,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 9999
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "LastFiveSales",
"Value": [
{
"SaleId": 701436,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-06-24T14:09:04Z",
"SalePrice": 289900.0,
"MunicipalityName": "CITY OF TSHWANE",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"SaleId": 698229,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-06-09T15:30:38Z",
"SalePrice": 299900.0,
"MunicipalityName": "CITY OF TSHWANE",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"SaleId": 695530,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-05-30T13:24:17Z",
"SalePrice": 289995.0,
"MunicipalityName": "CITY OF TSHWANE",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"SaleId": 685020,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-04-14T12:27:37Z",
"SalePrice": 366948.0,
"MunicipalityName": "EMFULENI",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"SaleId": 683843,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-04-11T15:00:38Z",
"SalePrice": 315500.0,
"MunicipalityName": "UMHLATHUZE",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
}
],
"ServiceResponsePropertyId": 481,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 0
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "ServiceStatus",
"Value": {
"StatusCode": 1,
"StatusDescription": "Ok",
"StatusDetail": "",
"RestServiceStatus": null,
"ServiceResource": null
},
"ServiceResponsePropertyId": 482,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13870410,
"SortOrder": 0
},
{
"EstimateType": "Auction",
"CarId": 0,
"Id": 1,
"SourceId": 1,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Auction Estimate",
"Value": 189400.0,
"ServiceResponsePropertyId": 494,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"EstimateType": "Cost",
"CarId": 0,
"Id": 2,
"SourceId": 2,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Cost Estimate",
"Value": 238300.0,
"ServiceResponsePropertyId": 495,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"EstimateType": "Cost",
"CarId": 0,
"Id": 3,
"SourceId": 3,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Cost Estimate High",
"Value": 259800.0,
"ServiceResponsePropertyId": 496,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 3
},
{
"EstimateType": "Cost",
"CarId": 0,
"Id": 4,
"SourceId": 4,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Cost Estimate Low",
"Value": 218700.0,
"ServiceResponsePropertyId": 497,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 2
},
{
"EstimateType": "Retail",
"CarId": 0,
"Id": 5,
"SourceId": 5,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Retail Estimate",
"Value": 300800.0,
"ServiceResponsePropertyId": 498,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"EstimateType": "Retail",
"CarId": 0,
"Id": 6,
"SourceId": 6,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Retail Estimate High",
"Value": 327900.0,
"ServiceResponsePropertyId": 499,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 3
},
{
"EstimateType": "Retail",
"CarId": 0,
"Id": 7,
"SourceId": 7,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Retail Estimate Low",
"Value": 276000.0,
"ServiceResponsePropertyId": 500,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 2
},
{
"EstimateType": "Trade",
"CarId": 0,
"Id": 8,
"SourceId": 8,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Trade Estimate",
"Value": 261300.0,
"ServiceResponsePropertyId": 501,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 1
},
{
"EstimateType": "Trade",
"CarId": 0,
"Id": 9,
"SourceId": 9,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Trade Estimate High",
"Value": 284900.0,
"ServiceResponsePropertyId": 502,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 3
},
{
"EstimateType": "Trade",
"CarId": 0,
"Id": 10,
"SourceId": 10,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Trade Estimate Low",
"Value": 239800.0,
"ServiceResponsePropertyId": 503,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13870410,
"SortOrder": 2
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 11,
"CategoryId": 7,
"Category": "Report",
"Description": "ReportUrl",
"Value": "https://pdf.lightstoneauto.co.za/Index.aspx?sourceurl=https://cdn.lightstoneauto.co.za/REPORTS/LIVE/f1a817b0-6b13-479a-b667-19d4ecd65a65.html",
"ServiceResponsePropertyId": 0,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 11,
"CategoryId": 7,
"Category": "Report",
"Description": "HtmlUrl",
"Value": "https://cdn.lightstoneauto.co.za/REPORTS/LIVE/f1a817b0-6b13-479a-b667-19d4ecd65a65.html",
"ServiceResponsePropertyId": 0,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
}
]
I want to only show certain items in the list,which are in "Value" like model, year, model etc..
My API function
Future<List<Vehicle>?> signInData() async {
final prefs = await SharedPreferences.getInstance();
final String? token = prefs.getString('token');
try {
Response response = await _dio.post('$_baseUrl/api/gateway',
data: {
"ClientPackageId": "0cdd231a-d7ad-4a68-a934-d373affb5100",
"PlatformId": "ios",
"ClientUserId": "AhmedOmar",
"VinNumber": VINumber
},
options: Options(
headers: {
"Content-Type": "application/json;charset=UTF-8",
"Charset": 'utf-8',
"Authorization": "Bearer $token",
},
));
print("data is here");
print(json.encode(response.data));
print(response.statusCode);
if (response.statusCode == 200) {
print("decoded");
final parsedJson = json.decode(json.encode(response.data));
print(
List<Vehicle>.from(parsedJson.map((job) => Vehicle.fromJson(job))));
return List<Vehicle>.from(
parsedJson.map((job) => Vehicle.fromJson(job)));
} else if (response.statusCode == 500) {
// call your refresh token api here and save it in shared preference
print(response.statusCode);
await getToken();
signInData();
} else {
throw Exception('Failed to load data');
}
} catch (e) {
print(e);
}
}
void showSnackBar(BuildContext context, String text) {
final snackBar = SnackBar(
content: Text(text),
duration: const Duration(seconds: 3), //default is 4s
);
// Find the Scaffold in the widget tree and use it to show a SnackBar.
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}
The results I want to achieve is below, shown in a picture
You can do something like this : List<Vehicle> _vehicleList;
instead of return statement write :
_vehicleList = List<Vehicle>.from(
parsedJson.map((job) => Vehicle.fromJson(job)));
and then after setState((){});
and I hope that you have ListView is available inside Build method
ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text($_vehicleList[index].category),
Text($_vehicleList[index].value),
],
);
},
itemCount: _vehicleList.length)

How to group weekly data in it respective months and plot using Apache Echarts

I have the weekly avg from last 5 years, last year, and the year to date.
I would like to show them in a line graph, but showing the respective months in the xaxis...
for example and based on this year:
January has 4 weeks, so xaxis shows jan and there are 4 marks in the chart representing weeks 1,2,3 and 4;
February also has 4 weeks, so xaxis shows feb and there are 3 marks in the chart representing week 5,6,7 and 8;
and so on;
i'm using:
VueJs: 2.6.10
Echarts: 4.9.0
here is my code:
// var motnhNames = [
// 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
// 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
// ]
var monthNames = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52
]
var options = {
title: {
text: 'My data'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['5 Years', 'Last Year', 'YTD']
},
toolbox: {
show: true,
feature: {
dataZoom: {
yAxisIndex: 'none'
},
dataView: {
readOnly: false
},
magicType: {
type: ['line', 'bar']
},
restore: {},
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: monthNames
},
yAxis: {
type: 'value',
},
series: [{
name: '5 Years',
type: 'line',
data: [
19, 46, 34, 33, 16, 3, 6, 33, 20,
25, 5, 29, 48, 36, 1, 28, 48, 1,
34, 22, 50, 38, 11, 11, 37, 11, 28,
15, 14, 5, 7, 2, 46, 3, 12, 10,
20, 50, 39, 17, 50, 7, 27, 6, 5,
11, 35, 25, 50, 18, 40, 30, 35
],
lineStyle: {
type: 'dashed',
width: 5
}
},
{
name: 'Last Year',
type: 'line',
data: [
17, 48, 30, 6, 29, 27, 8, 50, 28,
34, 38, 48, 28, 41, 24, 27, 15, 17,
13, 50, 9, 15, 18, 41, 43, 49, 19,
1, 22, 20, 27, 1, 18, 26, 48, 17,
25, 38, 1, 29, 28, 1, 42, 21, 7,
8, 6, 6, 47, 50, 6, 46, 41
],
lineStyle: {
type: 'dotted',
width: 5
}
},
{
name: 'YTD',
type: 'line',
data: [
17, 48, 30, 6, 29, 27, 8, 50, 28,
34, 38, 48, 28, 41, 24, 27, 15, 17,
13, 50, 9, 15, 18, 41, 43, 49, 19,
1, 22, 20, 27, 1, 18, 26, 48, 17,
25, 38, 1, 29, 28, 1, 42, 21, 7,
8, 6, 6, 47, 50, 6, 46
],
lineStyle: {
type: 'solid',
width: 5
}
}
]
};
thanks in advance
[UPDATE 1]
I added a function that translate the week number to the respective month:
getDateOfWeek(week: number, year: number): string {
let date = (1 + (week - 1) * 7);
let dateOfYear = new Date(year, 0, date)
let month = dateOfYear.toLocaleString('pt-BR', { month: 'short' });
month = month.charAt(0).toUpperCase() + month.slice(1).replace('.', '')
return month;
}
also added a axisLabel:
options: {
...,
axisLabel: {
formatter: (param: number) => {
return this.getDateOfWeek(param, 2021)
},
},
...,
}
Now i have the month name on xaxis as expected... Only need to suppress duplicated names or maybe define a limit for 12 ticks.
I've tried to use xaxis.splitNumber property, but as the docs says, it is not allowed for category axis...
I was wondering, if i could change the week number to a date object, like:
firstWeek = '2021-01-01'
secondWeek = '2021-01-08'
should i change it to time series and work with real dates on X Axis?
not sure if it would solve the problem or bring another :|
here is the result so far:
Solved adding a new xaxis layer and hide the first one...
xAxis: [
{
type: "category",
boundaryGap: false,
data: this.generateData(false, 51),
axisLabel: {
formatter: (param) => {
return this.getMonthFromWeek(param, 2021);
}
},
show: false
},
{
position: "bottom",
type: "category",
data: [
"Jan",
"Fev",
"Mar",
"Abr",
"Mai",
"Jun",
"Jul",
"Ago",
"Set",
"Out",
"Nov",
"Dez"
],
xAxisIndex: 2
}
],
here is sandbox code result!

Line Chart won't cover 100% of Horizontal Axis

I have a graph that won't cover the full chart area Horizontally
Here is the sample data that is used to achieve the graph
[
[
"2021-07-08",
53,
0,
53,
0,
38,
0
],
[
"2021-07-09",
11,
26,
27,
98,
20,
47
],
[
"2021-07-10",
80,
42,
14,
35,
20,
13
],
[
"2021-07-11",
16,
12,
17,
25,
47,
79
],
[
"2021-07-12",
41,
12,
10,
12,
64,
40
],
[
"2021-07-13",
32,
84,
30,
72,
19,
18
],
[
"2021-07-14",
12,
50,
44,
85,
25,
11
],
[
"2021-07-15",
43,
60,
26,
74,
88,
30
]
]
My options are
var options = {
legend: { position: 'bottom' },
chartArea:{left:20, right:0, top:0,width:'100%',height:'75%'}
};
See attached image with result
How do I make the Horizontal axis cover the whole chart?

How do I disable the secondary line that appears after clicking on a series in the legend of a Google chart?

If you look at this line chart and click on Dogs in the legend, you'll notice a secondary line appears next to the respective series in the graph.
How can I prevent this line from appearing? I'm aware that I can remove all interactivity by doing this:
var options = {
enableInteractivity: false
};
However, this will suppress tool tips as well. I only want to remove the interactivity in the legend.
you can override the chart's selection on the 'select' event,
if the selection row is null, then the legend is selected...
see following working snippet,
the selection is removed when the legend is selected...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = new google.visualization.DataTable();
data.addColumn('number', 'X');
data.addColumn('number', 'Dogs');
data.addColumn('number', 'Cats');
data.addRows([
[0, 0, 0], [1, 10, 5], [2, 23, 15], [3, 17, 9], [4, 18, 10], [5, 9, 5],
[6, 11, 3], [7, 27, 19], [8, 33, 25], [9, 40, 32], [10, 32, 24], [11, 35, 27],
[12, 30, 22], [13, 40, 32], [14, 42, 34], [15, 47, 39], [16, 44, 36], [17, 48, 40],
[18, 52, 44], [19, 54, 46], [20, 42, 34], [21, 55, 47], [22, 56, 48], [23, 57, 49],
[24, 60, 52], [25, 50, 42], [26, 52, 44], [27, 51, 43], [28, 49, 41], [29, 53, 45],
[30, 55, 47], [31, 60, 52], [32, 61, 53], [33, 59, 51], [34, 62, 54], [35, 65, 57],
[36, 62, 54], [37, 58, 50], [38, 55, 47], [39, 61, 53], [40, 64, 56], [41, 65, 57],
[42, 63, 55], [43, 66, 58], [44, 67, 59], [45, 69, 61], [46, 69, 61], [47, 70, 62],
[48, 72, 64], [49, 68, 60], [50, 66, 58], [51, 65, 57], [52, 67, 59], [53, 70, 62],
[54, 71, 63], [55, 72, 64], [56, 73, 65], [57, 75, 67], [58, 70, 62], [59, 68, 60],
[60, 64, 56], [61, 60, 52], [62, 65, 57], [63, 67, 59], [64, 68, 60], [65, 69, 61],
[66, 70, 62], [67, 72, 64], [68, 75, 67], [69, 80, 72]
]);
var options = {
hAxis: {
title: 'Time'
},
vAxis: {
title: 'Popularity'
},
series: {
1: {curveType: 'function'}
}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
google.visualization.events.addListener(chart, 'select', function () {
var selection = chart.getSelection();
if (selection.length > 0) {
if (selection[0].row === null) {
chart.setSelection([]);
}
}
});
chart.draw(data, options);
});
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>