I've tried following this and this and this, but I'm having issues getting the data from a string array.
I have my state set as
businessHours = : [
"Monday: 7:00 AM – 7:00 PM",
"Tuesday: 7:00 AM – 7:00 PM",
"Wednesday: 7:00 AM – 7:00 PM",
"Thursday: 7:00 AM – 7:00 PM",
"Friday: 7:00 AM – 7:00 PM",
"Saturday: 7:00 AM – 7:00 PM",
"Sunday: Closed"
]
This only gets me the first element from the array
ForEach(businessHours.indices) {
Text(self.businessHours[$0])
}
This fails
ForEach(businessHours.indices) {
Text(self.businessHours)
}
This works in the console
for businesshour in businessHours {
print("Hours: \(businesshour).")
}
What am I doing wrong here?
Here is a demo that works. Tested with Xcode 12 / iOS 14
struct DemoView: View {
let businessHours = [
"Monday: 7:00 AM – 7:00 PM",
"Tuesday: 7:00 AM – 7:00 PM",
"Wednesday: 7:00 AM – 7:00 PM",
"Thursday: 7:00 AM – 7:00 PM",
"Friday: 7:00 AM – 7:00 PM",
"Saturday: 7:00 AM – 7:00 PM",
"Sunday: Closed"
]
var body: some View {
VStack {
ForEach(businessHours.indices) {
Text(self.businessHours[$0])
}
}
}
}
There is a much simpler way..
When you have an array where the values are separated by ", " you can divide the array with this comma symbol
For Example: I have a user model with food. Food is an array, which looks similar like this:
user.food = ["Banana", "Strawberry", "Apple"]
You noticed: Every item is separated by the comma.
Now you can simply use
Text(user.food.joined(separator: ", "))
.multilineTextAlignment(.trailing)
.padding()
Et voilá :)
I figured it out.
(0..<businessHours.count, id: \.self) { index in
Text(self.businessHours[index])
}
Related
I have this struct created.
struct MedItem: Identifiable {
let id = UUID() //Generates a unique string for each item listed below
let medThumbnail: String
let medTitle: String
let medDose: String
let medDoseval: String
let purpose: String
let takeAt: String
let refillDate: String
let refillRem: String
}
With this data added:
struct MedData {
static let mListData = [
MedItem(medThumbnail: "Levo", medTitle: "Levothyroxine", medDose: "15", takeAt: "8 am", medDoseval: "mcg", purpose: "Hypothyroidism", refillDate: "December 3, 2021", refillRem: "Refill Remaning: 1"),
] //Imagine more sample data here
I'm trying to sort values based on time range linked to the timeAt value.
ForEach (meds, id: \.id) { MedItem in
HStack(spacing: 10.0){
}
If time is between 2am - 12pm then morning, 12pm - 3pm then noon, 3pm - 6pm evening, and 7pm - 2am then night. Some meds will not have a time and they need to be catoegorized in a different bucket.
Thank you for your help :)
models.Order.objects.filter(purchasedate__range=[from_date, to_date])
today_total = 0
quant = 0
for values in daterangeorder:
today_total += values.price
quant += values.quantity
return response.Response({
"from_date": from_date,
"to_date": to_date,
"Amount Sold": str(today_total),
"Count": str(quant)
})
This is the output:
{
"from_date": "2021-11-19",
"to_date": "2021-11-23",
"Amount Sold": "27000",
"Count": "9"
}
I want like this (day by day sold products count):-
{
date: “'2021-10-20”,
count: 20,
total_price_sold: 5000.00
},
{
date: “'2021-10-21”,
count: 4,
total_price_sold: 300.00
}
Instead of solving your problem with Python code, you can let the database handle it for you using aggregation, see the docs: https://docs.djangoproject.com/en/3.2/topics/db/aggregation/#values
from django.db.models import Sum
result = models.Order.objects.values('purchasedate')
.order_by('purchasedate')
.annotate(total_price_sold=Sum('price'), count=Sum('quantity'))
return response.Response(result)
My response body data:
"slots": {
"deliverySlots.today.text": {
"list": [
{
"pos": "004",
"deliverySlotCode": "8800652143353",
"deliveryDate": "Mar 20",
"beginTime": "10 am",
"endTime": "12 pm",
"dayOfWeek": "Tuesday",
"selected": false,
"expired": true,
"isAvailable": true
}
]
}
}
I would like to save the value of the isAvailable property into an environment variable. How can I set this value?
Given the data that you posted, you could add something like this to the Tests tab to create the variable.
var my_value = pm.response.json().slots['deliverySlots.today.text'].list[0].isAvailable
pm.environment.set('my_var', my_value)
This will only set the value that is in position 0 in your list array.
This part of the route deliverySlots.today.text needs to be wrapped in brackets [] as you cannot use the same dot notions to parse the JSON. It's quite a terrible naming convention so if you have any say over it, i'd recommend changing it.
I'm starting a new project that involves some IoT devices sending every 5 minutes their status and other info to AWS IoT.
The structure of the message is the following:
{
"SNC":"C_SN_15263217541",
"STATUS":"enable",
"PLANT":{
"PNAME":"nomeimpianto",
"DVS":{
"SD":[{
"SDSN":"LD_SN_15263987543",
"TT":"30/11/17 4:37 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125",
"ALCODE":"201",
"ALDESC":"assenza scarico"
},
{
"SDSN":"LD_SN_15263987543",
"TT":"30/11/17 4:39 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125",
"ALCODE":"201",
"ALDESC":"assenza scarico"
},
{
"SDSN":"LD_SN_15263997545",
"TT":"30/11/17 4:37 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125"
},
{
"SDSN":"LD_SN_15263997545",
"TT":"30/11/17 4:39 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125"
},
{
"SDSN":"LD_SN_15123987543",
"TT":"30/11/17 4:37 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125"
},
{
"SDSN":"LD_SN_15123987543",
"TT":"30/11/17 4:39 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125"
}
]
}
}
}
I created a rule that inserts the message on DynamoDB, and it's working nicely, but I'd need to create, for each message received, one row for each item in PLANT.DVS.SD.
My DynamoDB table has as hashkey the field PLANT.DVS.SD[x].SDSN and as sort field PLANT.DVS.SD[x].TT.
I tried with a DynamoDBv2 rule and I managed only to create one row per message with the whole array, but it's not what I'm looking for.
So basically the problem is that I don't know how to structure the SQL statement in the rule definition.
I know that PLANT.DVS.SD's max length is 12, so the only idea that I've got is to create 12 IoT rules that insert on DynamoDB only the element at a specific position. Although if there is a better way to solve this problem dynamically, it'd be appreciated!
Trying to make regex that can get state from address
1- 1234 Bellaire Blvd, Suite 123, Houston, TX 77036
2- 1234 BELLAIRE BL #123, HOUSTON, TX 77036
I have this for state
\w{2}(?=\s\d{1,5})
And this for Zip
(?<=\w{2}\s)\d{5}
FOR STATE
In 1st case above regex is returning "te" from "Suite" and TX for state which is correct
However, in 2nd case it is returning nothing
FOR ZIP
77036 is returned in 1st case and null is returned in 2nd case
I don't think regular expressions are the best way to do this. Rather I'd use an API to parse the address into it's components. You will need state_abbreviation and you're sorted. Example response:
[
{
"input_index": 0,
"candidate_index": 0,
"delivery_line_1": "1 Santa Claus Ln",
"last_line": "North Pole AK 99705-9901",
"delivery_point_barcode": "997059901010",
"components": {
"primary_number": "1",
"street_name": "Santa Claus",
"street_suffix": "Ln",
"city_name": "North Pole",
"state_abbreviation": "AK",
"zipcode": "99705",
"plus4_code": "9901",
"delivery_point": "01",
"delivery_point_check_digit": "0"
},
"metadata": {
"record_type": "S",
"zip_type": "Standard",
"county_fips": "02090",
"county_name": "Fairbanks North Star",
"carrier_route": "C004",
"congressional_district": "AL",
"rdi": "Commercial",
"elot_sequence": "0001",
"elot_sort": "A",
"latitude": 64.75233,
"longitude": -147.35297,
"precision": "Zip8",
"time_zone": "Alaska",
"utc_offset": -9,
"dst": true
},
"analysis": {
"dpv_match_code": "Y",
"dpv_footnotes": "AABB",
"dpv_cmra": "N",
"dpv_vacant": "N",
"active": "Y",
"footnotes": "L#"
}
},
{
"input_index": 1,
"candidate_index": 0,
"addressee": "Apple Inc",
"delivery_line_1": "1 Infinite Loop",
// truncated for brevity
}
]
Hope that helped.
You can match against ', ([A-Z]{2}) ' the state will then be the subpattern matched by the parentheses. In python it would look like this.
import re
s1 = "1- 1234 Bellaire Blvd, Suite 123, Houston, TX 77036"
s2 = "2- 1234 BELLAIRE BL #123, HOUSTON, TX 77036"
m = re.search(', ([A-Z]{2}) ', s1)
print(m.group(1))