Explore all Automotive related open source software, libraries, packages, source code, cloud functions and APIs.

The automotive industry comprises a wide range of companies and organizations involved in the design, development, manufacturing, marketing, and selling of motor vehicles. It is one of the world's largest industries by revenue.

These software components cover functions across Autonomous Driving, Connected Car, Dealer Management, Electric Vehicle, Fleet, Ridesharing areas.

Popular New Releases in Automotive

redisson

react-static

cryptomator

1.6.8

aeron

OpenBot

v0.3.2

Popular Libraries in Automotive

redisson

by redisson doticonjavadoticon

star image 18262 doticonApache-2.0

Redisson - Redis Java client with features of In-Memory Data Grid. Over 50 Redis based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Publish / Subscribe, Bloom filter, Spring Cache, Tomcat, Scheduler, JCache API, Hibernate, MyBatis, RPC, local cache ...

react-static

by react-static doticonjavascriptdoticon

star image 9762 doticonMIT

⚛️ 🚀 A progressive static site generator for React.

cryptomator

by cryptomator doticonjavadoticon

star image 7273 doticonGPL-3.0

Multi-platform transparent client-side encryption of your files in the cloud

aeron

by real-logic doticonjavadoticon

star image 5954 doticonApache-2.0

Efficient reliable UDP unicast, UDP multicast, and IPC message transport

lucida

by claritylab doticonjavadoticon

star image 4839 doticonNOASSERTION

Speech and Vision Based Intelligent Personal Assistant

research

by commaai doticonpythondoticon

star image 3984 doticonBSD-3-Clause

dataset and code for 2016 paper "Learning a Driving Simulator"

self-driving-car-sim

by udacity doticoncsharpdoticon

star image 3627 doticonMIT

A self-driving car simulator built with Unity

Object-Detection-Metrics

by rafaelpadilla doticonpythondoticon

star image 3616 doticonMIT

Most popular metrics used to evaluate object detection algorithms.

cannon.js

by schteppe doticonjavascriptdoticon

star image 3573 doticonNOASSERTION

A lightweight 3D physics engine written in JavaScript.

Trending New libraries in Automotive

OpenBot

by intel-isl doticonjavadoticon

star image 1827 doticonMIT

OpenBot leverages smartphones as brains for low-cost robots. We have designed a small electric vehicle that costs about $50 and serves as a robot body. Our software stack for Android smartphones supports advanced robotics workloads such as person following and real-time autonomous navigation.

DRouter

by didi doticonjavadoticon

star image 503 doticonApache-2.0

Android Router Framework

spike-prime

by gpdaniels doticonpythondoticon

star image 125 doticonMIT

Experiments with the LEGO Mindstorms (51515) and SPIKE Prime (45678)

tesla-style-solar-power-card

by reptilex doticontypescriptdoticon

star image 114 doticon

Home assistant power card mimicking the one tesla provides for the powerwall app.

social-driving

by fidler-lab doticonpythondoticon

star image 107 doticonMIT

Design multi-agent environments and simple reward functions such that social driving behavior emerges

Quest

by hverlin doticonjavascriptdoticon

star image 63 doticonMIT

Quest is a Unified Engine for Searching Things (JIRA, Confluence, Google Drive, Dropbox paper, Slack...)

deepseqslam

by mchancan doticonpythondoticon

star image 60 doticonGPL-3.0

The Official Deep Learning Framework for Robot Place Recognition

State Estimation and Localization of an autonomous vehicle based on IMU (high rate), GNSS (GPS) and Lidar data with sensor fusion techniques using the Extended Kalman Filter (EKF).

PurpleExplorer

by telstrapurple doticoncsharpdoticon

star image 58 doticonMIT

cross-platform Azure Service Bus explorer (Windows, MacOS, Linux)

Top Authors in Automotive

1

microsoft

5 Libraries

star icon157

2

GoogleCloudPlatform

4 Libraries

star icon97

3

Labs64

4 Libraries

star icon32

4

IBM

4 Libraries

star icon57

5

Azure-Samples

3 Libraries

star icon43

6

ndlibersa

3 Libraries

star icon18

7

choerodon

3 Libraries

star icon88

8

composiv

3 Libraries

star icon36

9

gyver98

3 Libraries

star icon53

10

piomin

3 Libraries

star icon53

1

5 Libraries

star icon157

2

4 Libraries

star icon97

3

4 Libraries

star icon32

4

4 Libraries

star icon57

5

3 Libraries

star icon43

6

3 Libraries

star icon18

7

3 Libraries

star icon88

8

3 Libraries

star icon36

9

3 Libraries

star icon53

10

3 Libraries

star icon53

Trending Kits in Automotive

No Trending Kits are available at this moment for Automotive

Trending Discussions on Automotive

trying to scrape 2 tags using beautifulsoup and placing them in the same csv

Android Auto app doesn't show up on physical device

Python coding standard for Safety Critical Applications

AOSP emulator memory filling up very quickly

Automated testing in Android Automotive

I Want To Fetch Only data With A Specific Field Value On Firebase

Does Android Automotive have the same ecosystem as normal Android?

Why do I get total count while using a group by clause?

What is the "right way" to signal specific instances of QML objects from C++?

Use output of one statement as input for another (recursively)

QUESTION

trying to scrape 2 tags using beautifulsoup and placing them in the same csv

Asked 2022-Apr-15 at 06:42

Im learning python currently and trying to do my own projects by taking pieces of other codes so don't fault me while I'm learning.

Im taking a list of stocks from tickers.csv and scraped a website to get sector & industry and place them on a stocks.csv

the problem is I can only get either the sector or industry (by choosing one) into the stocks.csv by

1if __name__ == '__main__':
2        to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
3        # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
4

I would like to get both sector and industry done at the same time here is the whole code

1if __name__ == '__main__':
2        to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
3        # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
4# dependencies
5import pandas as pd
6import requests
7from bs4 import BeautifulSoup as bs
8
9LSE = 'https://csimarket.com/stocks/at_glance.php?code='
10
11
12def get_stocks():
13    df = pd.read_csv('watchlist/tickers.csv')
14    return list(df['ticker'])
15
16
17def to_csv(stocks):
18    df = pd.DataFrame(stocks)
19    df.to_csv('stocks.csv', index=False)
20
21
22def get_soup(url):
23    return bs(requests.get(url).text, 'html.parser')
24
25
26def get_sector(ticker):
27    soup = get_soup(LSE + ticker)
28    try:
29        sector = soup.find('span', text='Sector').find_next('a').text.replace('\n', '').replace('•', '').strip()
30    except:
31        print('No sector information availible for ', ticker)
32        return {'ticker': ticker, 'sector': ''}
33
34    print(ticker, sector)
35    return {'ticker': ticker, 'sector': sector}
36
37
38def get_industry(ticker):
39    soup1 = get_soup(LSE + ticker)
40    try:
41        industry = soup1.find('span', text='Industry').find_next('a').text.replace('\n', '').replace('•', '').strip()
42    except:
43        print('No industry information availible for ', ticker)
44        return {'ticker': ticker, 'industry': ''}
45
46    print(ticker, industry)
47    return {'ticker': ticker, 'industry': industry}
48
49
50if __name__ == '__main__':
51    to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
52    # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
53

here is the tickers.csv

1if __name__ == '__main__':
2        to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
3        # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
4# dependencies
5import pandas as pd
6import requests
7from bs4 import BeautifulSoup as bs
8
9LSE = 'https://csimarket.com/stocks/at_glance.php?code='
10
11
12def get_stocks():
13    df = pd.read_csv('watchlist/tickers.csv')
14    return list(df['ticker'])
15
16
17def to_csv(stocks):
18    df = pd.DataFrame(stocks)
19    df.to_csv('stocks.csv', index=False)
20
21
22def get_soup(url):
23    return bs(requests.get(url).text, 'html.parser')
24
25
26def get_sector(ticker):
27    soup = get_soup(LSE + ticker)
28    try:
29        sector = soup.find('span', text='Sector').find_next('a').text.replace('\n', '').replace('•', '').strip()
30    except:
31        print('No sector information availible for ', ticker)
32        return {'ticker': ticker, 'sector': ''}
33
34    print(ticker, sector)
35    return {'ticker': ticker, 'sector': sector}
36
37
38def get_industry(ticker):
39    soup1 = get_soup(LSE + ticker)
40    try:
41        industry = soup1.find('span', text='Industry').find_next('a').text.replace('\n', '').replace('•', '').strip()
42    except:
43        print('No industry information availible for ', ticker)
44        return {'ticker': ticker, 'industry': ''}
45
46    print(ticker, industry)
47    return {'ticker': ticker, 'industry': industry}
48
49
50if __name__ == '__main__':
51    to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
52    # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
53ticker,
54A
55AA
56AADI
57AAIC
58AAL
59AAN
60AAOI
61AAON
62AAP
63AAPL
64AAT
65AAU
66AAWW
67AB
68ABB
69ABBV
70ABC
71ABCB
72ABCL
73ABEO
74ABEV
75ABG
76ABIO
77ABM
78ABMD
79ABNB
80ABOS
81ABR
82ABSI
83ABST
84ABT
85ABTX
86ABUS
87ACA
88ACAD
89ACB
90ACC
91ACCD
92ACCO
93ACEL
94ACER
95ACET
96ACEV
97ACGL
98ACH
99ACHC
100ACHR
101ACHV
102ACI
103ACIU
104

here is the stocks.csv when I get the sectors

1if __name__ == '__main__':
2        to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
3        # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
4# dependencies
5import pandas as pd
6import requests
7from bs4 import BeautifulSoup as bs
8
9LSE = 'https://csimarket.com/stocks/at_glance.php?code='
10
11
12def get_stocks():
13    df = pd.read_csv('watchlist/tickers.csv')
14    return list(df['ticker'])
15
16
17def to_csv(stocks):
18    df = pd.DataFrame(stocks)
19    df.to_csv('stocks.csv', index=False)
20
21
22def get_soup(url):
23    return bs(requests.get(url).text, 'html.parser')
24
25
26def get_sector(ticker):
27    soup = get_soup(LSE + ticker)
28    try:
29        sector = soup.find('span', text='Sector').find_next('a').text.replace('\n', '').replace('•', '').strip()
30    except:
31        print('No sector information availible for ', ticker)
32        return {'ticker': ticker, 'sector': ''}
33
34    print(ticker, sector)
35    return {'ticker': ticker, 'sector': sector}
36
37
38def get_industry(ticker):
39    soup1 = get_soup(LSE + ticker)
40    try:
41        industry = soup1.find('span', text='Industry').find_next('a').text.replace('\n', '').replace('•', '').strip()
42    except:
43        print('No industry information availible for ', ticker)
44        return {'ticker': ticker, 'industry': ''}
45
46    print(ticker, industry)
47    return {'ticker': ticker, 'industry': industry}
48
49
50if __name__ == '__main__':
51    to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
52    # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
53ticker,
54A
55AA
56AADI
57AAIC
58AAL
59AAN
60AAOI
61AAON
62AAP
63AAPL
64AAT
65AAU
66AAWW
67AB
68ABB
69ABBV
70ABC
71ABCB
72ABCL
73ABEO
74ABEV
75ABG
76ABIO
77ABM
78ABMD
79ABNB
80ABOS
81ABR
82ABSI
83ABST
84ABT
85ABTX
86ABUS
87ACA
88ACAD
89ACB
90ACC
91ACCD
92ACCO
93ACEL
94ACER
95ACET
96ACEV
97ACGL
98ACH
99ACHC
100ACHR
101ACHV
102ACI
103ACIU
104ticker,sector
105A,Healthcare
106AA,Basic Materials
107AADI,
108AAIC,Services
109AAL,Transportation
110AAN,Services
111AAOI,Technology
112AAON,Capital Goods
113AAP,Retail
114AAPL,Technology
115AAT,Financial
116AAU,Basic Materials
117AAWW,Transportation
118AB,Financial
119ABB,Consumer Discretionary
120ABBV,Healthcare
121ABC,Retail
122ABCB,Financial
123ABCL,Healthcare
124ABEO,Healthcare
125ABEV,Consumer Non Cyclical
126ABG,Retail
127ABIO,Healthcare
128ABM,Services
129ABMD,Healthcare
130ABNB,Services
131ABOS,Healthcare
132ABR,Financial
133ABSI,Healthcare
134ABST,
135ABT,Healthcare
136ABTX,Financial
137ABUS,Healthcare
138ACA,Basic Materials
139ACAD,Healthcare
140ACB,
141ACC,Financial
142ACCD,Financial
143ACCO,Basic Materials
144ACEL,Services
145ACER,Healthcare
146ACET,Retail
147ACEV,Technology
148ACGL,Financial
149ACH,Basic Materials
150ACHC,Healthcare
151ACHR,Capital Goods
152ACHV,Healthcare
153ACI,Energy
154ACIU,
155

here is the stocks.csv when I get the industries

1if __name__ == '__main__':
2        to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
3        # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
4# dependencies
5import pandas as pd
6import requests
7from bs4 import BeautifulSoup as bs
8
9LSE = 'https://csimarket.com/stocks/at_glance.php?code='
10
11
12def get_stocks():
13    df = pd.read_csv('watchlist/tickers.csv')
14    return list(df['ticker'])
15
16
17def to_csv(stocks):
18    df = pd.DataFrame(stocks)
19    df.to_csv('stocks.csv', index=False)
20
21
22def get_soup(url):
23    return bs(requests.get(url).text, 'html.parser')
24
25
26def get_sector(ticker):
27    soup = get_soup(LSE + ticker)
28    try:
29        sector = soup.find('span', text='Sector').find_next('a').text.replace('\n', '').replace('•', '').strip()
30    except:
31        print('No sector information availible for ', ticker)
32        return {'ticker': ticker, 'sector': ''}
33
34    print(ticker, sector)
35    return {'ticker': ticker, 'sector': sector}
36
37
38def get_industry(ticker):
39    soup1 = get_soup(LSE + ticker)
40    try:
41        industry = soup1.find('span', text='Industry').find_next('a').text.replace('\n', '').replace('•', '').strip()
42    except:
43        print('No industry information availible for ', ticker)
44        return {'ticker': ticker, 'industry': ''}
45
46    print(ticker, industry)
47    return {'ticker': ticker, 'industry': industry}
48
49
50if __name__ == '__main__':
51    to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
52    # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
53ticker,
54A
55AA
56AADI
57AAIC
58AAL
59AAN
60AAOI
61AAON
62AAP
63AAPL
64AAT
65AAU
66AAWW
67AB
68ABB
69ABBV
70ABC
71ABCB
72ABCL
73ABEO
74ABEV
75ABG
76ABIO
77ABM
78ABMD
79ABNB
80ABOS
81ABR
82ABSI
83ABST
84ABT
85ABTX
86ABUS
87ACA
88ACAD
89ACB
90ACC
91ACCD
92ACCO
93ACEL
94ACER
95ACET
96ACEV
97ACGL
98ACH
99ACHC
100ACHR
101ACHV
102ACI
103ACIU
104ticker,sector
105A,Healthcare
106AA,Basic Materials
107AADI,
108AAIC,Services
109AAL,Transportation
110AAN,Services
111AAOI,Technology
112AAON,Capital Goods
113AAP,Retail
114AAPL,Technology
115AAT,Financial
116AAU,Basic Materials
117AAWW,Transportation
118AB,Financial
119ABB,Consumer Discretionary
120ABBV,Healthcare
121ABC,Retail
122ABCB,Financial
123ABCL,Healthcare
124ABEO,Healthcare
125ABEV,Consumer Non Cyclical
126ABG,Retail
127ABIO,Healthcare
128ABM,Services
129ABMD,Healthcare
130ABNB,Services
131ABOS,Healthcare
132ABR,Financial
133ABSI,Healthcare
134ABST,
135ABT,Healthcare
136ABTX,Financial
137ABUS,Healthcare
138ACA,Basic Materials
139ACAD,Healthcare
140ACB,
141ACC,Financial
142ACCD,Financial
143ACCO,Basic Materials
144ACEL,Services
145ACER,Healthcare
146ACET,Retail
147ACEV,Technology
148ACGL,Financial
149ACH,Basic Materials
150ACHC,Healthcare
151ACHR,Capital Goods
152ACHV,Healthcare
153ACI,Energy
154ACIU,
155ticker,industry
156A,Laboratory Analytical Instruments
157AA,Aluminum
158AADI,
159AAIC,Real Estate Operations
160AAL,Airline
161AAN,Rental & Leasing
162AAOI,Computer Networks
163AAON,Industrial Machinery and Components
164AAP,Automotive Aftermarket
165AAPL,Computer Hardware
166AAT,Real Estate Investment Trusts
167AAU,Metal Mining
168AAWW,Special Transportation Services
169AB,Investment Services
170ABB,Electric & Wiring Equipment
171ABBV,Biotechnology & Pharmaceuticals
172ABC,Pharmacy Services & Retail Drugstore
173ABCB,Regional Banks
174ABCL,Major Pharmaceutical Preparations
175ABEO,Major Pharmaceutical Preparations
176ABEV,Nonalcoholic Beverages
177ABG,Automotive Aftermarket
178ABIO,In Vitro & In Vivo Diagnostic Substances
179ABM,Professional Services
180ABMD,Medical Equipment & Supplies
181ABNB,Real Estate Operations
182ABOS,Biotechnology & Pharmaceuticals
183ABR,Real Estate Investment Trusts
184ABSI,Medical Laboratories
185ABST,
186ABT,Major Pharmaceutical Preparations
187ABTX,Commercial Banks
188ABUS,Major Pharmaceutical Preparations
189ACA,Miscellaneous Fabricated Products
190ACAD,Major Pharmaceutical Preparations
191ACB,
192ACC,Real Estate Investment Trusts
193ACCD,Blank Checks
194ACCO,Paper & Paper Products
195ACEL,Casinos & Gaming
196ACER,Major Pharmaceutical Preparations
197ACET,Pharmacy Services & Retail Drugstore
198ACEV,Semiconductors
199ACGL,Property & Casualty Insurance
200ACH,Aluminum
201ACHC,Healthcare Facilities
202ACHR,Aerospace & Defense
203ACHV,In Vitro & In Vivo Diagnostic Substances
204ACI,Coal Mining
205ACIU,
206

ANSWER

Answered 2022-Apr-15 at 06:42

Just combine your existing two functions into one and return the result from parsing via a single soup object

1if __name__ == '__main__':
2        to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
3        # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
4# dependencies
5import pandas as pd
6import requests
7from bs4 import BeautifulSoup as bs
8
9LSE = 'https://csimarket.com/stocks/at_glance.php?code='
10
11
12def get_stocks():
13    df = pd.read_csv('watchlist/tickers.csv')
14    return list(df['ticker'])
15
16
17def to_csv(stocks):
18    df = pd.DataFrame(stocks)
19    df.to_csv('stocks.csv', index=False)
20
21
22def get_soup(url):
23    return bs(requests.get(url).text, 'html.parser')
24
25
26def get_sector(ticker):
27    soup = get_soup(LSE + ticker)
28    try:
29        sector = soup.find('span', text='Sector').find_next('a').text.replace('\n', '').replace('•', '').strip()
30    except:
31        print('No sector information availible for ', ticker)
32        return {'ticker': ticker, 'sector': ''}
33
34    print(ticker, sector)
35    return {'ticker': ticker, 'sector': sector}
36
37
38def get_industry(ticker):
39    soup1 = get_soup(LSE + ticker)
40    try:
41        industry = soup1.find('span', text='Industry').find_next('a').text.replace('\n', '').replace('•', '').strip()
42    except:
43        print('No industry information availible for ', ticker)
44        return {'ticker': ticker, 'industry': ''}
45
46    print(ticker, industry)
47    return {'ticker': ticker, 'industry': industry}
48
49
50if __name__ == '__main__':
51    to_csv(list(map(lambda ticker: get_sector(ticker), get_stocks())))
52    # to_csv(list(map(lambda ticker: get_industry(ticker), get_stocks())))
53ticker,
54A
55AA
56AADI
57AAIC
58AAL
59AAN
60AAOI
61AAON
62AAP
63AAPL
64AAT
65AAU
66AAWW
67AB
68ABB
69ABBV
70ABC
71ABCB
72ABCL
73ABEO
74ABEV
75ABG
76ABIO
77ABM
78ABMD
79ABNB
80ABOS
81ABR
82ABSI
83ABST
84ABT
85ABTX
86ABUS
87ACA
88ACAD
89ACB
90ACC
91ACCD
92ACCO
93ACEL
94ACER
95ACET
96ACEV
97ACGL
98ACH
99ACHC
100ACHR
101ACHV
102ACI
103ACIU
104ticker,sector
105A,Healthcare
106AA,Basic Materials
107AADI,
108AAIC,Services
109AAL,Transportation
110AAN,Services
111AAOI,Technology
112AAON,Capital Goods
113AAP,Retail
114AAPL,Technology
115AAT,Financial
116AAU,Basic Materials
117AAWW,Transportation
118AB,Financial
119ABB,Consumer Discretionary
120ABBV,Healthcare
121ABC,Retail
122ABCB,Financial
123ABCL,Healthcare
124ABEO,Healthcare
125ABEV,Consumer Non Cyclical
126ABG,Retail
127ABIO,Healthcare
128ABM,Services
129ABMD,Healthcare
130ABNB,Services
131ABOS,Healthcare
132ABR,Financial
133ABSI,Healthcare
134ABST,
135ABT,Healthcare
136ABTX,Financial
137ABUS,Healthcare
138ACA,Basic Materials
139ACAD,Healthcare
140ACB,
141ACC,Financial
142ACCD,Financial
143ACCO,Basic Materials
144ACEL,Services
145ACER,Healthcare
146ACET,Retail
147ACEV,Technology
148ACGL,Financial
149ACH,Basic Materials
150ACHC,Healthcare
151ACHR,Capital Goods
152ACHV,Healthcare
153ACI,Energy
154ACIU,
155ticker,industry
156A,Laboratory Analytical Instruments
157AA,Aluminum
158AADI,
159AAIC,Real Estate Operations
160AAL,Airline
161AAN,Rental & Leasing
162AAOI,Computer Networks
163AAON,Industrial Machinery and Components
164AAP,Automotive Aftermarket
165AAPL,Computer Hardware
166AAT,Real Estate Investment Trusts
167AAU,Metal Mining
168AAWW,Special Transportation Services
169AB,Investment Services
170ABB,Electric & Wiring Equipment
171ABBV,Biotechnology & Pharmaceuticals
172ABC,Pharmacy Services & Retail Drugstore
173ABCB,Regional Banks
174ABCL,Major Pharmaceutical Preparations
175ABEO,Major Pharmaceutical Preparations
176ABEV,Nonalcoholic Beverages
177ABG,Automotive Aftermarket
178ABIO,In Vitro & In Vivo Diagnostic Substances
179ABM,Professional Services
180ABMD,Medical Equipment & Supplies
181ABNB,Real Estate Operations
182ABOS,Biotechnology & Pharmaceuticals
183ABR,Real Estate Investment Trusts
184ABSI,Medical Laboratories
185ABST,
186ABT,Major Pharmaceutical Preparations
187ABTX,Commercial Banks
188ABUS,Major Pharmaceutical Preparations
189ACA,Miscellaneous Fabricated Products
190ACAD,Major Pharmaceutical Preparations
191ACB,
192ACC,Real Estate Investment Trusts
193ACCD,Blank Checks
194ACCO,Paper & Paper Products
195ACEL,Casinos & Gaming
196ACER,Major Pharmaceutical Preparations
197ACET,Pharmacy Services & Retail Drugstore
198ACEV,Semiconductors
199ACGL,Property & Casualty Insurance
200ACH,Aluminum
201ACHC,Healthcare Facilities
202ACHR,Aerospace & Defense
203ACHV,In Vitro & In Vivo Diagnostic Substances
204ACI,Coal Mining
205ACIU,
206import pandas as pd
207import requests
208from bs4 import BeautifulSoup as bs
209
210LSE = 'https://csimarket.com/stocks/at_glance.php?code='
211
212def get_stocks():
213    df = pd.read_csv('watchlist/tickers.csv')
214    return list(df['ticker'])
215
216
217def to_csv(stocks):
218    df = pd.DataFrame(stocks)
219    df.to_csv('stocks.csv', encoding='utf-8-sig', index=False)
220
221
222def get_soup(url):
223    return bs(requests.get(url, headers = {'User-Agent':'Mozilla/5.0'}).text, 'html.parser')
224
225
226def get_data(ticker):
227    soup = get_soup(LSE + ticker)
228    try:
229        sector = soup.find('span', text='Sector').find_next('a').text.replace('\n', '').replace('•', '').strip()
230    except:
231        print('No sector information availible for ', ticker)
232        return {'ticker': ticker, 'sector': ''}
233
234    print(ticker, sector)
235    
236    try:
237        industry = soup.find('span', text='Industry').find_next('a').text.replace('\n', '').replace('•', '').strip()
238    except:
239        print('No industry information availible for ', ticker)
240        return {'ticker': ticker, 'industry': ''}
241
242    print(ticker, industry)
243    return {'ticker': ticker, 'sector': sector,  'industry': industry}
244
245if __name__ == '__main__':
246    to_csv(list(map(lambda ticker: get_data(ticker), get_stocks())))
247

Source https://stackoverflow.com/questions/71877807

QUESTION

Android Auto app doesn't show up on physical device

Asked 2022-Mar-23 at 08:04

Currently testing Android Auto, where we are now testing on a physical device (in a car). So far I have managed to get add working Android Auto support to an app, where we are drawing some basic templates. This works on the emulated DHU and the app shows and can be used. The problem is that when we are testing on a physical device, it doesn't show up. My app currently shows up in the emulated DHU. All the necessary developer settings are turned on, so this shouldn't be an issue.

As a control test I created a new project through Android Studio by using > Automotive > Media Service, just to make sure that it was actually possible to test on a physical device. With no modifications and a clean install on a device, the car recognizes the app and the app is available in the car through a cable connection (physical device).

I suspect there is something I am overlooking in the different manifests.

This is the shared manifest for the project app:

1<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2    package="com.example.itf_aa.shared">
3    
4    <application>
5        
6        <meta-data
7            android:name="com.google.android.gms.car.application"
8            android:resource="@xml/automotive_app_desc" />
9        
10        <meta-data android:name="androidx.car.app.minCarApiLevel"
11            android:value="1" />
12
13        <service
14            android:name="com.example.itf_aa.shared.MainGridService"
15            android:exported="true">
16            <intent-filter>
17                <action android:name="androidx.car.app.CarAppService" />
18            </intent-filter>
19        </service>
20
21    </application>
22
23</manifest>
24

Meanwhile this is the shared manifest of the control app:

1<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2    package="com.example.itf_aa.shared">
3    
4    <application>
5        
6        <meta-data
7            android:name="com.google.android.gms.car.application"
8            android:resource="@xml/automotive_app_desc" />
9        
10        <meta-data android:name="androidx.car.app.minCarApiLevel"
11            android:value="1" />
12
13        <service
14            android:name="com.example.itf_aa.shared.MainGridService"
15            android:exported="true">
16            <intent-filter>
17                <action android:name="androidx.car.app.CarAppService" />
18            </intent-filter>
19        </service>
20
21    </application>
22
23</manifest>
24<manifest xmlns:android="http://schemas.android.com/apk/res/android"
25package="com.example.myapplication.shared">
26
27<application android:appCategory="audio">
28
29    <meta-data
30        android:name="com.google.android.gms.car.application"
31        android:resource="@xml/automotive_app_desc" />
32
33    <!-- Main music service, provides media browsing and media playback services to
34     consumers through MediaBrowserService and MediaSession. Consumers connect to it through
35     MediaBrowser (for browsing) and MediaController (for playback control) -->
36    <service
37        android:name="com.example.myapplication.shared.MyMusicService"
38        android:exported="true">
39        <intent-filter>
40            <action android:name="android.media.browse.MediaBrowserService" />
41        </intent-filter>
42    </service>
43
44</application>
45

I suspect the problem is found in the intent filter, where seems to be the difference maker. Does anyone know if there is anything else I can use in the intent filter or how my manifests may be wrong? This is the only thing I suspect being the difference maker, as I don't see how the app category makes it any different. Why does the app show up physical devices when we use "android.media.browse.MediaBrowserService", but not when we use "androidx.car.app.CarAppService"?

I am grateful for any help I might get on this, so thank you for your time and help in advance. If I left something out or you need more details, let me know. ❤️

ANSWER

Answered 2022-Mar-23 at 08:04

Turns out the answer can be found here.

In order for your app to run on a real head unit (not the desktop head unit we provide), your app must be distributed through the Google Play Store. This ensures that your application has been tested and vetted for adherence to our guidelines. These guidelines ensure that your application is relevant to the car environment, as well as pass our driver distraction tests.

It had nothing to do with the manifests. Still not sure why sample projects bypass this, but must be some sort of whitelist for Google apps.

Answer: in order for testing on physical devices, you need to start an internal test track and accept the Android Auto addendum. Then deploy the test through Play Store.

Source https://stackoverflow.com/questions/71411345

QUESTION

Python coding standard for Safety Critical Applications

Asked 2022-Mar-20 at 15:46

Coming from C/C++ background, I am aware of coding standards that apply for Safety Critical applications (like the classic trio Medical-Automotive-Aerospace) in the context of embedded systems , such as MISRA, SEI CERT, Barr etc.

Skipping the question if it should or if it is applicable as a language, I want to create Python applications for embedded systems that -even vaguely- follow some safety standard, but couldn't find any by searching, except from generic Python coding standards (like PEP8)

Is there a Python coding guideline that specificallly apply to safety-critical systems ?

ANSWER

Answered 2022-Feb-02 at 08:46

Top layer safety standards for "functional safety" like IEC 61508 (industrial), ISO 26262 (automotive) or DO-178 (aerospace) etc come with a software part (for example IEC 61508-3), where they list a number of suitable programming languages. These are exclusively old languages proven in use for a long time, where all flaws and poorly-defined behavior is regarded as well-known and execution can be regarded as predictable.

In practice, for the highest safety levels it means that you are pretty much restricted to C with safe subset (MISRA C) or Ada with safe subset (SPARK). A bunch of other old languages like Modula-2, Pascal and Fortran are also mentioned, but the tool support for these in the context of modern safety MCUs is non-existent. As is support for Python for such MCUs.

Languages like Python and C++ are not even mentioned for the lowest safety levels, so between the lines they are dismissed as entirely unsuitable. Even less so than pure assembler, which is actually mentioned as something that may used for the lower safety levels.

Source https://stackoverflow.com/questions/69673807

QUESTION

AOSP emulator memory filling up very quickly

Asked 2022-Mar-02 at 16:53

I'm currently working with AOSP and building an app for the Android Automotive OS. I have compiled the same code (checked out from version control) on two different PCs (both running Ubuntu). On one of them (with an Intel CPU) the emulator starts up fine and the emulator is stable.

On the other PC (an AMD CPU) the emulator starts up, but will quickly crash with OutOfMemory errors. AOSP is quickly killing all processes, then its system processes and finally reboots due to 'System is deadlocked on memory'.

I found that the culprit is a system process. It hoards a lot of memory: the android.hardware.automotive.vehicle process is hoarding memory. It keeps growing very quickly and finally the OS reboots.

When I use the meminfo tool to inspect memory usage of the process, I find the following: The android.hardware.automotive.vehicle process is using over 2GB of RAM.

My questions thus are:

  1. Do you what is happening?
  2. How can I debug this system process?
  3. Why is the system process behaving differently on one PC compared to another PC?

ANSWER

Answered 2022-Mar-02 at 16:53

For those who ran into this issue:

After a lot of fiddling around, I found that adding custom vehicle properties to the VHAL definitions (think of the types.hal and DefaultConfig.h files) must be done very carefully. In my case, I added a vehicle property with VehiclePropertyChangeMode set to CONTINUOUS, but did not add a minimum and maximum sample rate. This caused the android.hardware.automotive.vehicle service to keep requesting more and more memory for some reason and finally the emulator would crash.

If you want to prevent this from happening, make sure to add a minSampleRate and maxSampleRate in your DefaultConfig.h file!

Source https://stackoverflow.com/questions/71301262

QUESTION

Automated testing in Android Automotive

Asked 2022-Feb-21 at 21:02

What are the best frameworks or tools for automated testing in Android Automotive?

I read about Spectatio but I couldn't find code examples or anything other than what's mentioned on the Android page.

ANSWER

Answered 2022-Feb-01 at 14:30

If you look into CATBox documentation, it's based on Spectatio framework. You can build and run catbox from AOSP by following Build CATBox documentation.

BTW, Are you looking for testing framework for your unbundled applications? (which means app will be installed to Android Automotive through Play or else) or, your Android Automotive builds with preinstalled apps?

Source https://stackoverflow.com/questions/70608427

QUESTION

I Want To Fetch Only data With A Specific Field Value On Firebase

Asked 2022-Feb-10 at 10:18

Here I have a collection of cars and bikes and don't want to fetch everything if users select they are looking for only Cars, there are 2 types of categories Vehicles and Motorcycles and in firestore I query them like:

1[{category: vehicles, modelYear: 2008 }, {category: motorcycles, modelYear: 2012}]
2
3

but is there a way to query only the one the user has selected, Like:

1[{category: vehicles, modelYear: 2008 }, {category: motorcycles, modelYear: 2012}]
2
3    const [results, setResults] = useState([])
4
5     useEffect(() => {
6           if(vehicles === true){
7            db.collection("automotive")
8            .orderBy("category == Vehicles")
9            .limit(5)
10            .get()
11            .then((collections) =>{
12              const auto = collections.docs.map((res) => res.data())
13              setResult(auto)
14             })
15           }
16      }, [])
17

ANSWER

Answered 2022-Feb-10 at 10:18

Firebase Firestore have provided proper method to put condition on query and limit works only when you use orderby on field :

1[{category: vehicles, modelYear: 2008 }, {category: motorcycles, modelYear: 2012}]
2
3    const [results, setResults] = useState([])
4
5     useEffect(() => {
6           if(vehicles === true){
7            db.collection("automotive")
8            .orderBy("category == Vehicles")
9            .limit(5)
10            .get()
11            .then((collections) =>{
12              const auto = collections.docs.map((res) => res.data())
13              setResult(auto)
14             })
15           }
16      }, [])
17db.collection("automotive")
18    .where("category == Vehicles")
19    .orderBy("modelYear")
20    .limit(5)
21    .get()
22    .then((collections) =>{
23        const auto = collections.docs.map((res) => res.data())
24        setResult(auto)
25     });
26

Source https://stackoverflow.com/questions/71063196

QUESTION

Does Android Automotive have the same ecosystem as normal Android?

Asked 2022-Feb-01 at 05:10

As the title said. Just need to be curious, last time I tried using Snapp Automotive's Android Automotive build for Raspberry Pi and it was able to detect APKs, however, it can't install APKs. Is Android Automotive based on Android?

ANSWER

Answered 2022-Feb-01 at 05:10

Yes. Android Automotive (AAOS) is Android. e.g. Volvo uses Android and Google services for their cars. PTAL https://developer.volvocars.com/android-automotive/ link for more detail for Volvo cars. Renault also announced EV car with Android Automotive. See https://9to5google.com/2021/09/06/android-automotive-renault-megane-e-tech-electric/

Source https://stackoverflow.com/questions/70770472

QUESTION

Why do I get total count while using a group by clause?

Asked 2022-Jan-26 at 14:33

I am trying to count employees (from employees table) per division (departments table) My approach was to

1SELECT d.division, COUNT (first_name) 
2FROM departments d, employees
3GROUP BY d.division
4

I receive a total count of all (1000) employees multiplied by a number of identical divisions (with different departments), e.g. if 'Hardware' division has 'Automotive' and 'Tools' departments, I get a count of 2000.

Counting it within one table works fine (departments are both inside the 'employees' and 'departments' tables)

1SELECT d.division, COUNT (first_name) 
2FROM departments d, employees
3GROUP BY d.division
4SELECT department, COUNT (first_name) 
5FROM employees
6GROUP BY department
7

{I have just started and there's not many ways to get feedback while studying by yourself}

ANSWER

Answered 2022-Jan-26 at 11:44
1SELECT d.division, COUNT (first_name) 
2FROM departments d, employees
3GROUP BY d.division
4SELECT department, COUNT (first_name) 
5FROM employees
6GROUP BY department
7SELECT d.division, COUNT (e.first_name) 
8 FROM departments d 
9 JOIN employees e on d.id=e.department_id
10GROUP BY d.division
11

This construction FROM departments d, employees is a "cross-join" between two tables

Source https://stackoverflow.com/questions/70862757

QUESTION

What is the "right way" to signal specific instances of QML objects from C++?

Asked 2022-Jan-21 at 23:02

Right up-front, I'll apologize: This is a monster question, but I wanted to provide what I hope is all of the pertinent details.

I've got a QML-based GUI that I was tasked with taking over and developing from proof-of-concept to release. I believe the GUI is based on an example provided by QT (Automotive, maybe?). The GUI is being compiled for web-assembly (emscripten) and features a "back-end data-client" which communicates with our hardware controller via a socket and communicates with the GUI via signals. The GUI is accessed via web browser and communicates with the Data_Client via QWebSocket.

Simple Block Diagram

The GUI proof was initially created with a very "flat" hierarchy where every element is created and managed within a single ApplicationWindow object in a single "main" QML file. A Data_Client object is instantiated there and all the other visual elements are children (at various levels) of the ApplicationWindow:

1ApplicationWindow {
2id: appWindow
3
4//various properties and stuff
5
6Item {
7    id: clientHolder
8    property Data_Client client
9}
10
11ColumnLayout {
12    id: mainLayout
13    anchors.fill: parent
14    layoutDirection: Qt.LeftToRight
15//And so on...
16

The Data_Client C++ currently emits various signals in response to various things that happen in the controller application. In the main .QML the signals are handled as follows:

1ApplicationWindow {
2id: appWindow
3
4//various properties and stuff
5
6Item {
7    id: clientHolder
8    property Data_Client client
9}
10
11ColumnLayout {
12    id: mainLayout
13    anchors.fill: parent
14    layoutDirection: Qt.LeftToRight
15//And so on...
16Connections {
17        target: client 
18    onNew_status_port_data:
19        {
20            textStatusPort.text = qdata;
21        }
22        onNew_status_data_act_on:
23        {
24            imageStatusData.source = "../imagine-assets/ledGoodRim.png";
25        }
26    //and so on...
27

What I'm trying to do is create a ChannelStatusPanel object that holds the various status fields and handles the updates to those fields (text, images, etc.) when it receives information from the Data_Client backend. There are multiple instances of this ChannelStatusPanel contained in a MainStatusPanel which is made visible or not from the main ApplicationWindow:

GUI Basic Layout

Having said all of that (Phew!), I come finally to my question(s). What is the correct way to signal a specific instance of the ChannelStatusPanel object from the Data_Client with the various data items needed to drive changes to the visual elements of the ChannelStatusPanel?

I thought I was being clever by defining a ChannelStatusObject to hold the values:

1ApplicationWindow {
2id: appWindow
3
4//various properties and stuff
5
6Item {
7    id: clientHolder
8    property Data_Client client
9}
10
11ColumnLayout {
12    id: mainLayout
13    anchors.fill: parent
14    layoutDirection: Qt.LeftToRight
15//And so on...
16Connections {
17        target: client 
18    onNew_status_port_data:
19        {
20            textStatusPort.text = qdata;
21        }
22        onNew_status_data_act_on:
23        {
24            imageStatusData.source = "../imagine-assets/ledGoodRim.png";
25        }
26    //and so on...
27Item {
28    id: channelStatusObject
29
30    property int channel
31    property int enabled    //Using the EnabledState enum 
32    property string mode
33    property int bitrate
34    property int dataActivity   //Using the LedState enum
35//and more...
36    property int packetCount
37}
38

In the ChannelStatusPanel.qml, I then created a ChannelStatusObject property and a slot to handle the property change:

1ApplicationWindow {
2id: appWindow
3
4//various properties and stuff
5
6Item {
7    id: clientHolder
8    property Data_Client client
9}
10
11ColumnLayout {
12    id: mainLayout
13    anchors.fill: parent
14    layoutDirection: Qt.LeftToRight
15//And so on...
16Connections {
17        target: client 
18    onNew_status_port_data:
19        {
20            textStatusPort.text = qdata;
21        }
22        onNew_status_data_act_on:
23        {
24            imageStatusData.source = "../imagine-assets/ledGoodRim.png";
25        }
26    //and so on...
27Item {
28    id: channelStatusObject
29
30    property int channel
31    property int enabled    //Using the EnabledState enum 
32    property string mode
33    property int bitrate
34    property int dataActivity   //Using the LedState enum
35//and more...
36    property int packetCount
37}
38property ChannelStatusObject statusObject
39
40    onStatusObjectChanged: { 
41//..do the stuff
42

From the Data_Client C++ I will get the information from the controller application and determine which "channel" I need to update. As I see it, I need to be able to do the following things:

  1. I need to determine which instance of ChannelStatusPanel I need to update. How do I intelligently get a reference to the instance I want to signal? Is that just accomplished through QObject::findChild()? Is there a better, faster, or smarter way?
  2. In the Data_Client C++, do I want to create an instance of ChannelStatusObject, set the various fields within it appropriately, and then set the ChannelStatusPanel instance's ChannelStatusObject property equal to the newly created ChannelStatusObject? Alternatively, is there a mechanism to get a reference to the Panel's ChannelStatusObject and set each of its properties (fields) to what I want? In C++, something like this:
1ApplicationWindow {
2id: appWindow
3
4//various properties and stuff
5
6Item {
7    id: clientHolder
8    property Data_Client client
9}
10
11ColumnLayout {
12    id: mainLayout
13    anchors.fill: parent
14    layoutDirection: Qt.LeftToRight
15//And so on...
16Connections {
17        target: client 
18    onNew_status_port_data:
19        {
20            textStatusPort.text = qdata;
21        }
22        onNew_status_data_act_on:
23        {
24            imageStatusData.source = "../imagine-assets/ledGoodRim.png";
25        }
26    //and so on...
27Item {
28    id: channelStatusObject
29
30    property int channel
31    property int enabled    //Using the EnabledState enum 
32    property string mode
33    property int bitrate
34    property int dataActivity   //Using the LedState enum
35//and more...
36    property int packetCount
37}
38property ChannelStatusObject statusObject
39
40    onStatusObjectChanged: { 
41//..do the stuff
42QQmlComponent component(&engine, "ChannelStatusObject.qml");
43QObject *statObj= component.create();
44
45QQmlProperty::write(statObj, "channel", 1)
46QQmlProperty::write(statObj, "bitrate", 5000);
47QQmlProperty::write(statObj, "enabled", 0);
48
49//Then something like using the pointer from #1, above, to set the Panel property
50//QObject *channelPanel;
51QQmlProperty::write(channelPanel, "statusObject", statObj)
52

Is there some other, more accepted or conventional paradigm for doing this? Is this too convoluted?

ANSWER

Answered 2022-Jan-21 at 22:18

I would go about this using Qt's model-view-controller (delegate) paradigm. That is, your C++ code should expose some list-like Q_PROPERTY of channel status objects, which in turn expose their own data as properties. This can be done using a QQmlListProperty, as demonstrated here.

However, if the list itself is controlled from C++ code -- that is, the QML code does not need to directly edit the model, but only control which ones are shown in the view and possibly modify existing elements -- then it can be something simpler like a QList of QObject-derived pointers. As long as you do emit a signal when changing the list, this should be fine:

1ApplicationWindow {
2id: appWindow
3
4//various properties and stuff
5
6Item {
7    id: clientHolder
8    property Data_Client client
9}
10
11ColumnLayout {
12    id: mainLayout
13    anchors.fill: parent
14    layoutDirection: Qt.LeftToRight
15//And so on...
16Connections {
17        target: client 
18    onNew_status_port_data:
19        {
20            textStatusPort.text = qdata;
21        }
22        onNew_status_data_act_on:
23        {
24            imageStatusData.source = "../imagine-assets/ledGoodRim.png";
25        }
26    //and so on...
27Item {
28    id: channelStatusObject
29
30    property int channel
31    property int enabled    //Using the EnabledState enum 
32    property string mode
33    property int bitrate
34    property int dataActivity   //Using the LedState enum
35//and more...
36    property int packetCount
37}
38property ChannelStatusObject statusObject
39
40    onStatusObjectChanged: { 
41//..do the stuff
42QQmlComponent component(&engine, "ChannelStatusObject.qml");
43QObject *statObj= component.create();
44
45QQmlProperty::write(statObj, "channel", 1)
46QQmlProperty::write(statObj, "bitrate", 5000);
47QQmlProperty::write(statObj, "enabled", 0);
48
49//Then something like using the pointer from #1, above, to set the Panel property
50//QObject *channelPanel;
51QQmlProperty::write(channelPanel, "statusObject", statObj)
52class ChannelStatus : public QObject
53{
54    Q_OBJECT
55public:
56    Q_PROPERTY(int channel READ channel CONSTANT)
57    Q_PROPERTY(int enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
58    // etc.
59};
60
61class Data_Client : public QObject
62{
63    Q_OBJECT
64public:
65    Q_PROPERTY(QList<ChannelStatus*> statusList READ statusList NOTIFY statusListChanged)
66    // ...
67};
68

The ChannelStatus class itself must be registered with the QML type system, so that it can be imported in QML documents. Additionally, the list property type will need to be registered as a metatype, either in the main function or as a static variable. Otherwise, only lists of actual QObject pointers are recognised and you would have to provide yours as such.

1ApplicationWindow {
2id: appWindow
3
4//various properties and stuff
5
6Item {
7    id: clientHolder
8    property Data_Client client
9}
10
11ColumnLayout {
12    id: mainLayout
13    anchors.fill: parent
14    layoutDirection: Qt.LeftToRight
15//And so on...
16Connections {
17        target: client 
18    onNew_status_port_data:
19        {
20            textStatusPort.text = qdata;
21        }
22        onNew_status_data_act_on:
23        {
24            imageStatusData.source = "../imagine-assets/ledGoodRim.png";
25        }
26    //and so on...
27Item {
28    id: channelStatusObject
29
30    property int channel
31    property int enabled    //Using the EnabledState enum 
32    property string mode
33    property int bitrate
34    property int dataActivity   //Using the LedState enum
35//and more...
36    property int packetCount
37}
38property ChannelStatusObject statusObject
39
40    onStatusObjectChanged: { 
41//..do the stuff
42QQmlComponent component(&engine, "ChannelStatusObject.qml");
43QObject *statObj= component.create();
44
45QQmlProperty::write(statObj, "channel", 1)
46QQmlProperty::write(statObj, "bitrate", 5000);
47QQmlProperty::write(statObj, "enabled", 0);
48
49//Then something like using the pointer from #1, above, to set the Panel property
50//QObject *channelPanel;
51QQmlProperty::write(channelPanel, "statusObject", statObj)
52class ChannelStatus : public QObject
53{
54    Q_OBJECT
55public:
56    Q_PROPERTY(int channel READ channel CONSTANT)
57    Q_PROPERTY(int enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
58    // etc.
59};
60
61class Data_Client : public QObject
62{
63    Q_OBJECT
64public:
65    Q_PROPERTY(QList<ChannelStatus*> statusList READ statusList NOTIFY statusListChanged)
66    // ...
67};
68qmlRegisterUncreatableType<ChannelStatus>("LibraryName", 1, 0, 
69    "ChannelStatus", "Property access only.");
70qRegisterMetaType<QList<ChannelStatus*>>();
71

You then use this property of the client on the QML side as the model property of a suitable QML component, such as a ListView or a Repeater inside a container like RowLayout. For example:

1ApplicationWindow {
2id: appWindow
3
4//various properties and stuff
5
6Item {
7    id: clientHolder
8    property Data_Client client
9}
10
11ColumnLayout {
12    id: mainLayout
13    anchors.fill: parent
14    layoutDirection: Qt.LeftToRight
15//And so on...
16Connections {
17        target: client 
18    onNew_status_port_data:
19        {
20            textStatusPort.text = qdata;
21        }
22        onNew_status_data_act_on:
23        {
24            imageStatusData.source = "../imagine-assets/ledGoodRim.png";
25        }
26    //and so on...
27Item {
28    id: channelStatusObject
29
30    property int channel
31    property int enabled    //Using the EnabledState enum 
32    property string mode
33    property int bitrate
34    property int dataActivity   //Using the LedState enum
35//and more...
36    property int packetCount
37}
38property ChannelStatusObject statusObject
39
40    onStatusObjectChanged: { 
41//..do the stuff
42QQmlComponent component(&engine, "ChannelStatusObject.qml");
43QObject *statObj= component.create();
44
45QQmlProperty::write(statObj, "channel", 1)
46QQmlProperty::write(statObj, "bitrate", 5000);
47QQmlProperty::write(statObj, "enabled", 0);
48
49//Then something like using the pointer from #1, above, to set the Panel property
50//QObject *channelPanel;
51QQmlProperty::write(channelPanel, "statusObject", statObj)
52class ChannelStatus : public QObject
53{
54    Q_OBJECT
55public:
56    Q_PROPERTY(int channel READ channel CONSTANT)
57    Q_PROPERTY(int enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
58    // etc.
59};
60
61class Data_Client : public QObject
62{
63    Q_OBJECT
64public:
65    Q_PROPERTY(QList<ChannelStatus*> statusList READ statusList NOTIFY statusListChanged)
66    // ...
67};
68qmlRegisterUncreatableType<ChannelStatus>("LibraryName", 1, 0, 
69    "ChannelStatus", "Property access only.");
70qRegisterMetaType<QList<ChannelStatus*>>();
71import LibraryName 1.0
72ListView {
73    model: client.statusList
74    delegate: Column {
75        Label { text: modelData.channel }
76        Image { source: modelData.enabled ? "foo" : "bar" }
77        // ...
78    }
79}
80

As you can see, the model data is implicitly attached to the delegate components. Any NOTIFYable properties will have their values automatically updated.

Source https://stackoverflow.com/questions/70685132

QUESTION

Use output of one statement as input for another (recursively)

Asked 2022-Jan-18 at 01:01

The product table is associated to the categories table via product.ext_category_id=categories.ext_id, however the ext_category_id might be associated to either a level 1, level 2, or level 3 category within the categories table.

I'm looking for a select statement that will select all of the products in the products table as well as the corresponding level 1 category from the category table.

product.id product.product_name categories.name
1 Strawberries Fruit & Vegetable department
2 Bananas Fruit & Vegetable department
3 Potatoes Fruit & Vegetable department
4 Car Battery Automotive department
5 Chips Junk Food department

If a product from the products table is associated to either a level 2 or level 3 category within the categories table, then you need to use the categories.parent_id to search the categories.id column within the categories table to find the next category, until you get the level 1 category.

I've spent a day trying to figure this out using various methods such as CASE and subqueries with the select statement, and recursive functions, but nothing worked. Sample CASE snippet -

1SELECT
2    product.id,
3    product.product_name,
4    CASE WHEN categories.level = '3' THEN (
5           SELECT c2.name
6           FROM categories c2
7           WHERE c2.id = categories.parent_id )
8    END AS level_2_cat_name
9FROM product
10    JOIN categories ON categories.ext_id = product.ext_category_id
11

Example product Table

id product_name ext_category_id
1 Strawberries 101
2 Bananas 102
3 Potatoes 103
4 Car Battery 104
5 Chips 105

Example categories Table

id ext_id name level parent_id
1001 101 Fruit 2 2000
1002 102 Fruit 2 2000
1003 103 Vegetables 2 2000
1004 104 Car Parts 3 2500
2001 209 Junk Food Department 1 Null

...

id ext_id name level parent_id
2000 205 Fruit & Vegetable department 1 Null
2000 205 Fruit & Vegetable department 1 Null
2000 205 Fruit & Vegetable department 1 Null
2500 309 Cars & Trucks 2 2002
2002 209 Automotive department 1 Null
2001 209 Junk Food department 1 Null

ANSWER

Answered 2022-Jan-18 at 01:01

Here's an example of using Recursive CTE to solve the problem. This will handle practically any number of category levels.

There are a few ways to do this.

Your test data had some mistakes. I've corrected them for this test.

Note: There was an outer join, because your initial data didn't have a matching category related to Chips. That can be removed if there is no missing data. I'm going to remove it now.

The fiddle

1SELECT
2    product.id,
3    product.product_name,
4    CASE WHEN categories.level = '3' THEN (
5           SELECT c2.name
6           FROM categories c2
7           WHERE c2.id = categories.parent_id )
8    END AS level_2_cat_name
9FROM product
10    JOIN categories ON categories.ext_id = product.ext_category_id
11WITH RECURSIVE cte1 (id, name, cid, cname, level, parent_id) AS (
12        SELECT p.id, p.product_name, c.id, c.name, level, parent_id
13          FROM product     AS p
14          JOIN categories  AS c
15            ON p.ext_category_id = c.ext_id
16         UNION ALL
17        SELECT p.id, p.name, c.id AS cid, c.name AS cname, c.level, c.parent_id
18          FROM cte1        AS p
19          JOIN categories  AS c
20            ON c.id = p.parent_id
21     )
22SELECT id, name, cname
23  FROM cte1
24 WHERE level = 1
25 ORDER BY id
26;
27

The result:

1SELECT
2    product.id,
3    product.product_name,
4    CASE WHEN categories.level = '3' THEN (
5           SELECT c2.name
6           FROM categories c2
7           WHERE c2.id = categories.parent_id )
8    END AS level_2_cat_name
9FROM product
10    JOIN categories ON categories.ext_id = product.ext_category_id
11WITH RECURSIVE cte1 (id, name, cid, cname, level, parent_id) AS (
12        SELECT p.id, p.product_name, c.id, c.name, level, parent_id
13          FROM product     AS p
14          JOIN categories  AS c
15            ON p.ext_category_id = c.ext_id
16         UNION ALL
17        SELECT p.id, p.name, c.id AS cid, c.name AS cname, c.level, c.parent_id
18          FROM cte1        AS p
19          JOIN categories  AS c
20            ON c.id = p.parent_id
21     )
22SELECT id, name, cname
23  FROM cte1
24 WHERE level = 1
25 ORDER BY id
26;
27+------+--------------+------------------------------+
28| id   | name         | cname                        |
29+------+--------------+------------------------------+
30|    1 | Strawberries | Fruit & Vegetable department |
31|    2 | Bananas      | Fruit & Vegetable department |
32|    3 | Potatoes     | Fruit & Vegetable department |
33|    4 | Car Battery  | Automotive department        |
34|    5 | Chips        | Junk Food Department         |
35+------+--------------+------------------------------+
36

The setup:

1SELECT
2    product.id,
3    product.product_name,
4    CASE WHEN categories.level = '3' THEN (
5           SELECT c2.name
6           FROM categories c2
7           WHERE c2.id = categories.parent_id )
8    END AS level_2_cat_name
9FROM product
10    JOIN categories ON categories.ext_id = product.ext_category_id
11WITH RECURSIVE cte1 (id, name, cid, cname, level, parent_id) AS (
12        SELECT p.id, p.product_name, c.id, c.name, level, parent_id
13          FROM product     AS p
14          JOIN categories  AS c
15            ON p.ext_category_id = c.ext_id
16         UNION ALL
17        SELECT p.id, p.name, c.id AS cid, c.name AS cname, c.level, c.parent_id
18          FROM cte1        AS p
19          JOIN categories  AS c
20            ON c.id = p.parent_id
21     )
22SELECT id, name, cname
23  FROM cte1
24 WHERE level = 1
25 ORDER BY id
26;
27+------+--------------+------------------------------+
28| id   | name         | cname                        |
29+------+--------------+------------------------------+
30|    1 | Strawberries | Fruit & Vegetable department |
31|    2 | Bananas      | Fruit & Vegetable department |
32|    3 | Potatoes     | Fruit & Vegetable department |
33|    4 | Car Battery  | Automotive department        |
34|    5 | Chips        | Junk Food Department         |
35+------+--------------+------------------------------+
36CREATE TABLE product (
37    id               int
38  , product_name     varchar(40)
39  , ext_category_id  int
40);
41
42INSERT INTO product VALUES
43  ( 1, 'Strawberries' , 101)
44, ( 2, 'Bananas'      , 102)
45, ( 3, 'Potatoes'     , 103)
46, ( 4, 'Car Battery'  , 104)
47, ( 5, 'Chips'        , 105)
48;
49
50CREATE TABLE categories (
51    id           int
52  , ext_id       int
53  , name         varchar(40)
54  , level        int
55  , parent_id    int
56);
57
58-- id   ext_id  name    level   parent_id
59INSERT INTO categories VALUES
60  (1001, 101, 'Fruit'                , 2, 2000)
61, (1002, 102, 'Fruit'                , 2, 2000)
62, (1003, 103, 'Vegetables'           , 2, 2000)
63, (1004, 104, 'Car Parts'            , 3, 2500)
64, (1005, 105, 'FoodParts'            , 2, 2001)
65, (2001, 209, 'Junk Food Department' , 1, Null)
66, (2000, 205, 'Fruit & Vegetable department', 1, Null)
67, (2500, 309, 'Cars & Trucks'               , 2, 2002)
68, (2002, 209, 'Automotive department'       , 1, Null)
69;
70

Source https://stackoverflow.com/questions/70748475

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in Automotive

Tutorials and Learning Resources are not available at this moment for Automotive

Share this Page

share link

Get latest updates on Automotive