Explore all 5G open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in 5G

free5gc

v3.1.1

ngic-rtc

experimental release

my5G-RANTester

v1.0.0

ProtoCentral_ads1262

v1.0.0

epcforedge

OpenNESS 20.12.02 Release

Popular Libraries in 5G

free5gc

by free5gc doticongodoticon

star image 1361 doticonApache-2.0

Open source 5G core network base on 3GPP R15

open5gs

by open5gs doticoncdoticon

star image 827 doticonAGPL-3.0

Open5GS is a C-language Open Source implementation for 5G Core and EPC, i.e. the core network of LTE/NR network (Release-16)

oor

by OpenOverlayRouter doticoncdoticon

star image 92 doticonApache-2.0

OpenOverlayRouter is an implementation to create programmable overlay networks.

NFV_LTE_EPC

by networkedsystemsIITB doticonc++doticon

star image 59 doticon

A Virtualized Evolved Packet Core for LTE Networks

ZodiacFX

by NorthboundNetworks doticoncdoticon

star image 55 doticonGPL-3.0

Firmware for the Northbound Networks Zodiac FX OpenFlow Switch

ngic-rtc

by omec-project doticoncdoticon

star image 45 doticonApache-2.0

NGIC-RTC is Control User Plane Separated (CUPS) architecture 3GPP TS23501 based implementation of EPC Service and Packet Gateway functions (SGW, PGW)

New_Radio_5G_Utils

by prtkmishra doticonpythondoticon

star image 41 doticon

This repository contains Physical layer utilities based on 3GPP specs for NR 5G

qingzhenyun-core

by qingzhenyun doticonjavadoticon

star image 35 doticonMIT

Qingzhenyun(6pan Core Service)

free5gc-stage-3

by free5gc doticongodoticon

star image 26 doticonApache-2.0

Open source 5G core network base on 3GPP R15

Trending New libraries in 5G

free5gc

by free5gc doticongodoticon

star image 1361 doticonApache-2.0

Open source 5G core network base on 3GPP R15

free5gc-stage-3

by free5gc doticongodoticon

star image 26 doticonApache-2.0

Open source 5G core network base on 3GPP R15

my5G-RANTester

by my5G doticongodoticon

star image 22 doticonApache-2.0

my5G-RANTester is a gNB/UE simulator for testing 3GPP standards and stressing a 5G core.

tool3rd

by proj3rd doticontypescriptdoticon

star image 6 doticonMIT

Assistant for 3GPP telecommunication development

Top Authors in 5G

1

networkedsystemsIITB

2 Libraries

star icon78

2

free5gc

2 Libraries

star icon1387

3

proj3rd

2 Libraries

star icon12

4

my5G

1 Libraries

star icon22

5

Protocentral

1 Libraries

star icon19

6

qingzhenyun

1 Libraries

star icon35

7

hont127

1 Libraries

star icon3

8

1gate

1 Libraries

star icon2

9

HyGlobalHD

1 Libraries

star icon2

10

prtkmishra

1 Libraries

star icon41

1

2 Libraries

star icon78

2

2 Libraries

star icon1387

3

2 Libraries

star icon12

4

1 Libraries

star icon22

5

1 Libraries

star icon19

6

1 Libraries

star icon35

7

1 Libraries

star icon3

8

1 Libraries

star icon2

9

1 Libraries

star icon2

10

1 Libraries

star icon41

Trending Kits in 5G

No Trending Kits are available at this moment for 5G

Trending Discussions on 5G

How to fix "NVRM: API mismatch" between client version and kernel module version when installing Nvidia drivers for a GTX 560 Ti in Ubuntu 20.04?

App using Realtime database not working in Romania ISPs blocked by Firebase

Dummy coding syntax (one hot coding question)

Conditioning the soup selection on a web scrape.Python/BeautifulSoup

OpenGL Shader Compilation Error Android 12 Samsung Galaxy S21

Mongodb: How to pass another stage inside $group?

Combine duplicate tokens inside huge JSON file into nested array of objects using React

What does Kubelet use to determine the ephemeral-storage capacity of the node?

Create list of strings from nested list of indices and nested list of strings

My emulator date input type has a forward slash (/), my device does not?

QUESTION

How to fix "NVRM: API mismatch" between client version and kernel module version when installing Nvidia drivers for a GTX 560 Ti in Ubuntu 20.04?

Asked 2022-Apr-03 at 18:54

I have installed nvidia-driver-390 after adding a GTX 560 Ti on an Intel Core i5 12600K PC running Kubuntu 20.04 LTS.

After rebooting I get the following error:

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6

How do I get that client version set to 390.144?

Newer drivers such as nvidia-driver-460 do not seem to support this video card. Also I get a warning:

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6$ ubuntu-drivers devices
7WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
8== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
9modalias : pci:v000010DEd00001200sv00001043sd000083ACbc03sc00i00
10vendor   : NVIDIA Corporation
11model    : GF114 [GeForce GTX 560 Ti]
12driver   : nvidia-340 - distro non-free
13driver   : nvidia-driver-390 - distro non-free recommended
14driver   : xserver-xorg-video-nouveau - distro free builtin
15

I run a newer kernel in order to have networking with the Intel 2.5G Ethernet IGC driver. I can boot into kernel 5.4.0.91-generic, but then I won't have a network.

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6$ ubuntu-drivers devices
7WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
8== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
9modalias : pci:v000010DEd00001200sv00001043sd000083ACbc03sc00i00
10vendor   : NVIDIA Corporation
11model    : GF114 [GeForce GTX 560 Ti]
12driver   : nvidia-340 - distro non-free
13driver   : nvidia-driver-390 - distro non-free recommended
14driver   : xserver-xorg-video-nouveau - distro free builtin
15$ uname -a
16Linux Kairos 5.13.0-22-generic #22~20.04.1-Ubuntu SMP Tue Nov 9 15:07:24 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
17

Furthermore, dkms gives:

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6$ ubuntu-drivers devices
7WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
8== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
9modalias : pci:v000010DEd00001200sv00001043sd000083ACbc03sc00i00
10vendor   : NVIDIA Corporation
11model    : GF114 [GeForce GTX 560 Ti]
12driver   : nvidia-340 - distro non-free
13driver   : nvidia-driver-390 - distro non-free recommended
14driver   : xserver-xorg-video-nouveau - distro free builtin
15$ uname -a
16Linux Kairos 5.13.0-22-generic #22~20.04.1-Ubuntu SMP Tue Nov 9 15:07:24 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
17$ dkms status
18nvidia, 390.144, 5.13.0-22-generic, x86_64: installed
19nvidia, 390.144, 5.4.0-91-generic, x86_64: built
20

While /var/lib/dkms/ shows:

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6$ ubuntu-drivers devices
7WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
8== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
9modalias : pci:v000010DEd00001200sv00001043sd000083ACbc03sc00i00
10vendor   : NVIDIA Corporation
11model    : GF114 [GeForce GTX 560 Ti]
12driver   : nvidia-340 - distro non-free
13driver   : nvidia-driver-390 - distro non-free recommended
14driver   : xserver-xorg-video-nouveau - distro free builtin
15$ uname -a
16Linux Kairos 5.13.0-22-generic #22~20.04.1-Ubuntu SMP Tue Nov 9 15:07:24 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
17$ dkms status
18nvidia, 390.144, 5.13.0-22-generic, x86_64: installed
19nvidia, 390.144, 5.4.0-91-generic, x86_64: built
20$ tree /var/lib/dkms/
21/var/lib/dkms/
22├── dkms_dbversion
23└── nvidia
24    ├── 390.144
25    │   ├── 5.13.0-22-generic
26    │   │   └── x86_64
27    │   │       ├── log
28    │   │       │   └── make.log
29    │   │       └── module
30    │   │           ├── nvidia-drm.ko
31    │   │           ├── nvidia.ko
32    │   │           └── nvidia-modeset.ko
33    │   ├── 5.4.0-91-generic
34    │   │   └── x86_64
35    │   │       ├── log
36    │   │       │   └── make.log
37    │   │       └── module
38    │   │           ├── nvidia-drm.ko
39    │   │           ├── nvidia.ko
40    │   │           ├── nvidia-modeset.ko
41    │   │           └── nvidia-uvm.ko
42    │   └── source -> /usr/src/nvidia-390.144
43    └── kernel-5.13.0-22-generic-x86_64 -> 390.144/5.13.0-22-generic/x86_64
44
4512 directories, 10 files
46

And modinfo nvidia returns:

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6$ ubuntu-drivers devices
7WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
8== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
9modalias : pci:v000010DEd00001200sv00001043sd000083ACbc03sc00i00
10vendor   : NVIDIA Corporation
11model    : GF114 [GeForce GTX 560 Ti]
12driver   : nvidia-340 - distro non-free
13driver   : nvidia-driver-390 - distro non-free recommended
14driver   : xserver-xorg-video-nouveau - distro free builtin
15$ uname -a
16Linux Kairos 5.13.0-22-generic #22~20.04.1-Ubuntu SMP Tue Nov 9 15:07:24 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
17$ dkms status
18nvidia, 390.144, 5.13.0-22-generic, x86_64: installed
19nvidia, 390.144, 5.4.0-91-generic, x86_64: built
20$ tree /var/lib/dkms/
21/var/lib/dkms/
22├── dkms_dbversion
23└── nvidia
24    ├── 390.144
25    │   ├── 5.13.0-22-generic
26    │   │   └── x86_64
27    │   │       ├── log
28    │   │       │   └── make.log
29    │   │       └── module
30    │   │           ├── nvidia-drm.ko
31    │   │           ├── nvidia.ko
32    │   │           └── nvidia-modeset.ko
33    │   ├── 5.4.0-91-generic
34    │   │   └── x86_64
35    │   │       ├── log
36    │   │       │   └── make.log
37    │   │       └── module
38    │   │           ├── nvidia-drm.ko
39    │   │           ├── nvidia.ko
40    │   │           ├── nvidia-modeset.ko
41    │   │           └── nvidia-uvm.ko
42    │   └── source -> /usr/src/nvidia-390.144
43    └── kernel-5.13.0-22-generic-x86_64 -> 390.144/5.13.0-22-generic/x86_64
44
4512 directories, 10 files
46filename:       /lib/modules/5.13.0-22-generic/updates/dkms/nvidia.ko
47alias:          char-major-195-*
48version:        390.144
49supported:      external
50license:        NVIDIA
51srcversion:     D635B75826DE88984609590
52alias:          pci:v000010DEd00000E00sv*sd*bc04sc80i00*
53alias:          pci:v000010DEd*sv*sd*bc03sc02i00*
54alias:          pci:v000010DEd*sv*sd*bc03sc00i00*
55depends:        ipmi_msghandler
56retpoline:      Y
57name:           nvidia
58vermagic:       5.13.0-22-generic SMP mod_unload modversions 
59parm:           NVreg_Mobile:int
60parm:           NVreg_ResmanDebugLevel:int
61parm:           NVreg_RmLogonRC:int
62parm:           NVreg_ModifyDeviceFiles:int
63parm:           NVreg_DeviceFileUID:int
64parm:           NVreg_DeviceFileGID:int
65parm:           NVreg_DeviceFileMode:int
66parm:           NVreg_UpdateMemoryTypes:int
67parm:           NVreg_InitializeSystemMemoryAllocations:int
68parm:           NVreg_UsePageAttributeTable:int
69parm:           NVreg_MapRegistersEarly:int
70parm:           NVreg_RegisterForACPIEvents:int
71parm:           NVreg_CheckPCIConfigSpace:int
72parm:           NVreg_EnablePCIeGen3:int
73parm:           NVreg_EnableMSI:int
74parm:           NVreg_TCEBypassMode:int
75parm:           NVreg_UseThreadedInterrupts:int
76parm:           NVreg_EnableStreamMemOPs:int
77parm:           NVreg_EnableBacklightHandler:int
78parm:           NVreg_RestrictProfilingToAdminUsers:int
79parm:           NVreg_EnableUserNUMAManagement:int
80parm:           NVreg_EnableIBMNPURelaxedOrderingMode:int
81parm:           NVreg_MemoryPoolSize:int
82parm:           NVreg_KMallocHeapMaxSize:int
83parm:           NVreg_VMallocHeapMaxSize:int
84parm:           NVreg_IgnoreMMIOCheck:int
85parm:           NVreg_RegistryDwords:charp
86parm:           NVreg_RegistryDwordsPerDevice:charp
87parm:           NVreg_RmMsg:charp
88parm:           NVreg_AssignGpus:charp
89

I have found many posts about how to upgrade the driver to the latest version, currently 495, however it does not solve my problem and that version does not support my video card. Only version 390 works, but then I get that API mismatch error.

ANSWER

Answered 2021-Dec-13 at 16:51

I found the solution and now Kubuntu starts up normally as expected.

First, I purged all drivers and libraries

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6$ ubuntu-drivers devices
7WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
8== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
9modalias : pci:v000010DEd00001200sv00001043sd000083ACbc03sc00i00
10vendor   : NVIDIA Corporation
11model    : GF114 [GeForce GTX 560 Ti]
12driver   : nvidia-340 - distro non-free
13driver   : nvidia-driver-390 - distro non-free recommended
14driver   : xserver-xorg-video-nouveau - distro free builtin
15$ uname -a
16Linux Kairos 5.13.0-22-generic #22~20.04.1-Ubuntu SMP Tue Nov 9 15:07:24 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
17$ dkms status
18nvidia, 390.144, 5.13.0-22-generic, x86_64: installed
19nvidia, 390.144, 5.4.0-91-generic, x86_64: built
20$ tree /var/lib/dkms/
21/var/lib/dkms/
22├── dkms_dbversion
23└── nvidia
24    ├── 390.144
25    │   ├── 5.13.0-22-generic
26    │   │   └── x86_64
27    │   │       ├── log
28    │   │       │   └── make.log
29    │   │       └── module
30    │   │           ├── nvidia-drm.ko
31    │   │           ├── nvidia.ko
32    │   │           └── nvidia-modeset.ko
33    │   ├── 5.4.0-91-generic
34    │   │   └── x86_64
35    │   │       ├── log
36    │   │       │   └── make.log
37    │   │       └── module
38    │   │           ├── nvidia-drm.ko
39    │   │           ├── nvidia.ko
40    │   │           ├── nvidia-modeset.ko
41    │   │           └── nvidia-uvm.ko
42    │   └── source -> /usr/src/nvidia-390.144
43    └── kernel-5.13.0-22-generic-x86_64 -> 390.144/5.13.0-22-generic/x86_64
44
4512 directories, 10 files
46filename:       /lib/modules/5.13.0-22-generic/updates/dkms/nvidia.ko
47alias:          char-major-195-*
48version:        390.144
49supported:      external
50license:        NVIDIA
51srcversion:     D635B75826DE88984609590
52alias:          pci:v000010DEd00000E00sv*sd*bc04sc80i00*
53alias:          pci:v000010DEd*sv*sd*bc03sc02i00*
54alias:          pci:v000010DEd*sv*sd*bc03sc00i00*
55depends:        ipmi_msghandler
56retpoline:      Y
57name:           nvidia
58vermagic:       5.13.0-22-generic SMP mod_unload modversions 
59parm:           NVreg_Mobile:int
60parm:           NVreg_ResmanDebugLevel:int
61parm:           NVreg_RmLogonRC:int
62parm:           NVreg_ModifyDeviceFiles:int
63parm:           NVreg_DeviceFileUID:int
64parm:           NVreg_DeviceFileGID:int
65parm:           NVreg_DeviceFileMode:int
66parm:           NVreg_UpdateMemoryTypes:int
67parm:           NVreg_InitializeSystemMemoryAllocations:int
68parm:           NVreg_UsePageAttributeTable:int
69parm:           NVreg_MapRegistersEarly:int
70parm:           NVreg_RegisterForACPIEvents:int
71parm:           NVreg_CheckPCIConfigSpace:int
72parm:           NVreg_EnablePCIeGen3:int
73parm:           NVreg_EnableMSI:int
74parm:           NVreg_TCEBypassMode:int
75parm:           NVreg_UseThreadedInterrupts:int
76parm:           NVreg_EnableStreamMemOPs:int
77parm:           NVreg_EnableBacklightHandler:int
78parm:           NVreg_RestrictProfilingToAdminUsers:int
79parm:           NVreg_EnableUserNUMAManagement:int
80parm:           NVreg_EnableIBMNPURelaxedOrderingMode:int
81parm:           NVreg_MemoryPoolSize:int
82parm:           NVreg_KMallocHeapMaxSize:int
83parm:           NVreg_VMallocHeapMaxSize:int
84parm:           NVreg_IgnoreMMIOCheck:int
85parm:           NVreg_RegistryDwords:charp
86parm:           NVreg_RegistryDwordsPerDevice:charp
87parm:           NVreg_RmMsg:charp
88parm:           NVreg_AssignGpus:charp
89$ sudo apt purge nvidia-* && sudo apt purge libnvidia-*
90

Then I checked if there weren't any nvidia drivers installed. The following did not return anything, as it should

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6$ ubuntu-drivers devices
7WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
8== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
9modalias : pci:v000010DEd00001200sv00001043sd000083ACbc03sc00i00
10vendor   : NVIDIA Corporation
11model    : GF114 [GeForce GTX 560 Ti]
12driver   : nvidia-340 - distro non-free
13driver   : nvidia-driver-390 - distro non-free recommended
14driver   : xserver-xorg-video-nouveau - distro free builtin
15$ uname -a
16Linux Kairos 5.13.0-22-generic #22~20.04.1-Ubuntu SMP Tue Nov 9 15:07:24 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
17$ dkms status
18nvidia, 390.144, 5.13.0-22-generic, x86_64: installed
19nvidia, 390.144, 5.4.0-91-generic, x86_64: built
20$ tree /var/lib/dkms/
21/var/lib/dkms/
22├── dkms_dbversion
23└── nvidia
24    ├── 390.144
25    │   ├── 5.13.0-22-generic
26    │   │   └── x86_64
27    │   │       ├── log
28    │   │       │   └── make.log
29    │   │       └── module
30    │   │           ├── nvidia-drm.ko
31    │   │           ├── nvidia.ko
32    │   │           └── nvidia-modeset.ko
33    │   ├── 5.4.0-91-generic
34    │   │   └── x86_64
35    │   │       ├── log
36    │   │       │   └── make.log
37    │   │       └── module
38    │   │           ├── nvidia-drm.ko
39    │   │           ├── nvidia.ko
40    │   │           ├── nvidia-modeset.ko
41    │   │           └── nvidia-uvm.ko
42    │   └── source -> /usr/src/nvidia-390.144
43    └── kernel-5.13.0-22-generic-x86_64 -> 390.144/5.13.0-22-generic/x86_64
44
4512 directories, 10 files
46filename:       /lib/modules/5.13.0-22-generic/updates/dkms/nvidia.ko
47alias:          char-major-195-*
48version:        390.144
49supported:      external
50license:        NVIDIA
51srcversion:     D635B75826DE88984609590
52alias:          pci:v000010DEd00000E00sv*sd*bc04sc80i00*
53alias:          pci:v000010DEd*sv*sd*bc03sc02i00*
54alias:          pci:v000010DEd*sv*sd*bc03sc00i00*
55depends:        ipmi_msghandler
56retpoline:      Y
57name:           nvidia
58vermagic:       5.13.0-22-generic SMP mod_unload modversions 
59parm:           NVreg_Mobile:int
60parm:           NVreg_ResmanDebugLevel:int
61parm:           NVreg_RmLogonRC:int
62parm:           NVreg_ModifyDeviceFiles:int
63parm:           NVreg_DeviceFileUID:int
64parm:           NVreg_DeviceFileGID:int
65parm:           NVreg_DeviceFileMode:int
66parm:           NVreg_UpdateMemoryTypes:int
67parm:           NVreg_InitializeSystemMemoryAllocations:int
68parm:           NVreg_UsePageAttributeTable:int
69parm:           NVreg_MapRegistersEarly:int
70parm:           NVreg_RegisterForACPIEvents:int
71parm:           NVreg_CheckPCIConfigSpace:int
72parm:           NVreg_EnablePCIeGen3:int
73parm:           NVreg_EnableMSI:int
74parm:           NVreg_TCEBypassMode:int
75parm:           NVreg_UseThreadedInterrupts:int
76parm:           NVreg_EnableStreamMemOPs:int
77parm:           NVreg_EnableBacklightHandler:int
78parm:           NVreg_RestrictProfilingToAdminUsers:int
79parm:           NVreg_EnableUserNUMAManagement:int
80parm:           NVreg_EnableIBMNPURelaxedOrderingMode:int
81parm:           NVreg_MemoryPoolSize:int
82parm:           NVreg_KMallocHeapMaxSize:int
83parm:           NVreg_VMallocHeapMaxSize:int
84parm:           NVreg_IgnoreMMIOCheck:int
85parm:           NVreg_RegistryDwords:charp
86parm:           NVreg_RegistryDwordsPerDevice:charp
87parm:           NVreg_RmMsg:charp
88parm:           NVreg_AssignGpus:charp
89$ sudo apt purge nvidia-* && sudo apt purge libnvidia-*
90$ dpkg -l nvidia-*|grep ^ii
91

Then I downloaded the correct version of drivers for my Geforce GTX 560 Ti from https://www.nvidia.com/Download/driverResults.aspx/177153/en-us. You should select your driver from https://www.nvidia.com/Download/index.aspx?lang=en-us.

After this I rebooted into a terminal

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6$ ubuntu-drivers devices
7WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
8== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
9modalias : pci:v000010DEd00001200sv00001043sd000083ACbc03sc00i00
10vendor   : NVIDIA Corporation
11model    : GF114 [GeForce GTX 560 Ti]
12driver   : nvidia-340 - distro non-free
13driver   : nvidia-driver-390 - distro non-free recommended
14driver   : xserver-xorg-video-nouveau - distro free builtin
15$ uname -a
16Linux Kairos 5.13.0-22-generic #22~20.04.1-Ubuntu SMP Tue Nov 9 15:07:24 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
17$ dkms status
18nvidia, 390.144, 5.13.0-22-generic, x86_64: installed
19nvidia, 390.144, 5.4.0-91-generic, x86_64: built
20$ tree /var/lib/dkms/
21/var/lib/dkms/
22├── dkms_dbversion
23└── nvidia
24    ├── 390.144
25    │   ├── 5.13.0-22-generic
26    │   │   └── x86_64
27    │   │       ├── log
28    │   │       │   └── make.log
29    │   │       └── module
30    │   │           ├── nvidia-drm.ko
31    │   │           ├── nvidia.ko
32    │   │           └── nvidia-modeset.ko
33    │   ├── 5.4.0-91-generic
34    │   │   └── x86_64
35    │   │       ├── log
36    │   │       │   └── make.log
37    │   │       └── module
38    │   │           ├── nvidia-drm.ko
39    │   │           ├── nvidia.ko
40    │   │           ├── nvidia-modeset.ko
41    │   │           └── nvidia-uvm.ko
42    │   └── source -> /usr/src/nvidia-390.144
43    └── kernel-5.13.0-22-generic-x86_64 -> 390.144/5.13.0-22-generic/x86_64
44
4512 directories, 10 files
46filename:       /lib/modules/5.13.0-22-generic/updates/dkms/nvidia.ko
47alias:          char-major-195-*
48version:        390.144
49supported:      external
50license:        NVIDIA
51srcversion:     D635B75826DE88984609590
52alias:          pci:v000010DEd00000E00sv*sd*bc04sc80i00*
53alias:          pci:v000010DEd*sv*sd*bc03sc02i00*
54alias:          pci:v000010DEd*sv*sd*bc03sc00i00*
55depends:        ipmi_msghandler
56retpoline:      Y
57name:           nvidia
58vermagic:       5.13.0-22-generic SMP mod_unload modversions 
59parm:           NVreg_Mobile:int
60parm:           NVreg_ResmanDebugLevel:int
61parm:           NVreg_RmLogonRC:int
62parm:           NVreg_ModifyDeviceFiles:int
63parm:           NVreg_DeviceFileUID:int
64parm:           NVreg_DeviceFileGID:int
65parm:           NVreg_DeviceFileMode:int
66parm:           NVreg_UpdateMemoryTypes:int
67parm:           NVreg_InitializeSystemMemoryAllocations:int
68parm:           NVreg_UsePageAttributeTable:int
69parm:           NVreg_MapRegistersEarly:int
70parm:           NVreg_RegisterForACPIEvents:int
71parm:           NVreg_CheckPCIConfigSpace:int
72parm:           NVreg_EnablePCIeGen3:int
73parm:           NVreg_EnableMSI:int
74parm:           NVreg_TCEBypassMode:int
75parm:           NVreg_UseThreadedInterrupts:int
76parm:           NVreg_EnableStreamMemOPs:int
77parm:           NVreg_EnableBacklightHandler:int
78parm:           NVreg_RestrictProfilingToAdminUsers:int
79parm:           NVreg_EnableUserNUMAManagement:int
80parm:           NVreg_EnableIBMNPURelaxedOrderingMode:int
81parm:           NVreg_MemoryPoolSize:int
82parm:           NVreg_KMallocHeapMaxSize:int
83parm:           NVreg_VMallocHeapMaxSize:int
84parm:           NVreg_IgnoreMMIOCheck:int
85parm:           NVreg_RegistryDwords:charp
86parm:           NVreg_RegistryDwordsPerDevice:charp
87parm:           NVreg_RmMsg:charp
88parm:           NVreg_AssignGpus:charp
89$ sudo apt purge nvidia-* && sudo apt purge libnvidia-*
90$ dpkg -l nvidia-*|grep ^ii
91$ sudo init 3
92

I logged in on the command line and went to the directory where I just downloaded the driver, then changed permissions and ran the installation file (it may ask some configuration questions), followed by a reboot

1$ dmesg|grep -i nvrm -A3
2[  113.647054] NVRM: API mismatch: the client has the version 460.91.03, but
3               NVRM: this kernel module has the version 390.144.  Please
4               NVRM: make sure that this kernel module and all NVIDIA driver
5               NVRM: components have the same version.
6$ ubuntu-drivers devices
7WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
8== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
9modalias : pci:v000010DEd00001200sv00001043sd000083ACbc03sc00i00
10vendor   : NVIDIA Corporation
11model    : GF114 [GeForce GTX 560 Ti]
12driver   : nvidia-340 - distro non-free
13driver   : nvidia-driver-390 - distro non-free recommended
14driver   : xserver-xorg-video-nouveau - distro free builtin
15$ uname -a
16Linux Kairos 5.13.0-22-generic #22~20.04.1-Ubuntu SMP Tue Nov 9 15:07:24 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
17$ dkms status
18nvidia, 390.144, 5.13.0-22-generic, x86_64: installed
19nvidia, 390.144, 5.4.0-91-generic, x86_64: built
20$ tree /var/lib/dkms/
21/var/lib/dkms/
22├── dkms_dbversion
23└── nvidia
24    ├── 390.144
25    │   ├── 5.13.0-22-generic
26    │   │   └── x86_64
27    │   │       ├── log
28    │   │       │   └── make.log
29    │   │       └── module
30    │   │           ├── nvidia-drm.ko
31    │   │           ├── nvidia.ko
32    │   │           └── nvidia-modeset.ko
33    │   ├── 5.4.0-91-generic
34    │   │   └── x86_64
35    │   │       ├── log
36    │   │       │   └── make.log
37    │   │       └── module
38    │   │           ├── nvidia-drm.ko
39    │   │           ├── nvidia.ko
40    │   │           ├── nvidia-modeset.ko
41    │   │           └── nvidia-uvm.ko
42    │   └── source -> /usr/src/nvidia-390.144
43    └── kernel-5.13.0-22-generic-x86_64 -> 390.144/5.13.0-22-generic/x86_64
44
4512 directories, 10 files
46filename:       /lib/modules/5.13.0-22-generic/updates/dkms/nvidia.ko
47alias:          char-major-195-*
48version:        390.144
49supported:      external
50license:        NVIDIA
51srcversion:     D635B75826DE88984609590
52alias:          pci:v000010DEd00000E00sv*sd*bc04sc80i00*
53alias:          pci:v000010DEd*sv*sd*bc03sc02i00*
54alias:          pci:v000010DEd*sv*sd*bc03sc00i00*
55depends:        ipmi_msghandler
56retpoline:      Y
57name:           nvidia
58vermagic:       5.13.0-22-generic SMP mod_unload modversions 
59parm:           NVreg_Mobile:int
60parm:           NVreg_ResmanDebugLevel:int
61parm:           NVreg_RmLogonRC:int
62parm:           NVreg_ModifyDeviceFiles:int
63parm:           NVreg_DeviceFileUID:int
64parm:           NVreg_DeviceFileGID:int
65parm:           NVreg_DeviceFileMode:int
66parm:           NVreg_UpdateMemoryTypes:int
67parm:           NVreg_InitializeSystemMemoryAllocations:int
68parm:           NVreg_UsePageAttributeTable:int
69parm:           NVreg_MapRegistersEarly:int
70parm:           NVreg_RegisterForACPIEvents:int
71parm:           NVreg_CheckPCIConfigSpace:int
72parm:           NVreg_EnablePCIeGen3:int
73parm:           NVreg_EnableMSI:int
74parm:           NVreg_TCEBypassMode:int
75parm:           NVreg_UseThreadedInterrupts:int
76parm:           NVreg_EnableStreamMemOPs:int
77parm:           NVreg_EnableBacklightHandler:int
78parm:           NVreg_RestrictProfilingToAdminUsers:int
79parm:           NVreg_EnableUserNUMAManagement:int
80parm:           NVreg_EnableIBMNPURelaxedOrderingMode:int
81parm:           NVreg_MemoryPoolSize:int
82parm:           NVreg_KMallocHeapMaxSize:int
83parm:           NVreg_VMallocHeapMaxSize:int
84parm:           NVreg_IgnoreMMIOCheck:int
85parm:           NVreg_RegistryDwords:charp
86parm:           NVreg_RegistryDwordsPerDevice:charp
87parm:           NVreg_RmMsg:charp
88parm:           NVreg_AssignGpus:charp
89$ sudo apt purge nvidia-* && sudo apt purge libnvidia-*
90$ dpkg -l nvidia-*|grep ^ii
91$ sudo init 3
92$ cd $HOME/Downloads/Nvidia/
93$ chmod a+x NVIDIA-Linux-x86_64-390.144.run
94$ sudo ./NVIDIA-Linux-x86_64-390.144.run 
95$ sudo reboot
96

I now had my normal GDM login screen and after logging in my dual screens were both in the correct resolution.

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

QUESTION

App using Realtime database not working in Romania ISPs blocked by Firebase

Asked 2022-Mar-29 at 13:21

I'm facing a critical issue right now in Romania. So for almost 24 hours my mobile app which is using Firebase Realtime Database can't be used on some ISPs (like Vodafone, DIGI or Telekom) if you are using mobile data (4G or 5G) the app is working fine, but on Wi-fi (on these ISPs the app is getting timeout). I talked like several hours on the phone with multiple ISPs and the Firebase support (right now the app is working using DIGI, but nobody knows why). The ISPs are saying that problem is not on their end and Firebase is saying that the problem is on the ISP side. Firebase support answer:

As this has been caused by network issues, rather than Google's infrastructure, we can't do much about it from our end. I would recommend that you contact the ISP provider directly as they will be able to check deeper on their side.

As far as we can see, the multiple providers are affected by that issue. Our engineering team is already aware of that and looking for solutions. Like I said before, there is nothing we could do with the providers, but our engineers would find any suitable workaround.

So my question is: what can I do? (I saw that Firebase realtime database deployed in europe-west works) but mine is already on united states.

Is there someone having troubles like me? I tested multiple apps which I know are using Firebase and they are having the same issues, the app being unreachable over this type of network.

Updates on the issue: enter image description here

So the problem is regarding Ukraine and Russia :(. Many apps using Firebase Realtime Database are not working right now.

Below I posted a fix for this and how I handled in order to make my app functional again

ANSWER

Answered 2022-Mar-29 at 13:21

So for someone who is in Europe and has the same issue like me, this is what i did.

I made a new instance of a realtime database on europe-west (because this one works on every ISP). I migrated my old database to the new one. I pushed for release a new iOS and Android build using the new database. I disabled my old instance in order to not have any syncing problems. I made all of this at night hours like 24:00.

I the morning all users would have the new update. If someone is not going to have the update until 10 AM I have set a push notification to announce this changes.

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

QUESTION

Dummy coding syntax (one hot coding question)

Asked 2022-Mar-24 at 11:13

I have sample data that looks like this:

1id <- c("1a","2c","3d","4f","5g","6e","7f","8q","9r","10v","11x","12l")
2O <- c(1,1,0,1,1,0,0,1,0,1,0,1)
3dg1 <- c("A02","A84","B12","C94","D37","D12","D68","E12","F48","H12","Z83","")
4dg2 <- c("B18","N34","A02","M01","B12","J02","K52","","I10","","","B18")
5df <- cbind.data.frame(id,O,dg1,dg2)
6

I am trying to get a data frame that looks like this so that I can do a univariate logistic regression on O against each variable.

1id <- c("1a","2c","3d","4f","5g","6e","7f","8q","9r","10v","11x","12l")
2O <- c(1,1,0,1,1,0,0,1,0,1,0,1)
3dg1 <- c("A02","A84","B12","C94","D37","D12","D68","E12","F48","H12","Z83","")
4dg2 <- c("B18","N34","A02","M01","B12","J02","K52","","I10","","","B18")
5df <- cbind.data.frame(id,O,dg1,dg2)
6A02 <- c(1,0,1,0,0,0,0,0,0,0,0,0)
7A84 <- c(0,1,0,0,0,0,0,0,0,0,0,0)
8B12 <- c(0,0,1,0,1,0,0,0,0,0,0,0)
9B18 <- c(1,0,0,0,0,0,0,0,0,0,0,1)
10C94 <- c(0,0,0,1,0,0,0,0,0,0,0,0)
11D12 <- c(0,0,0,0,0,1,0,0,0,0,0,0)
12D37 <- c(0,0,0,0,1,0,0,0,0,0,0,0)
13D68 <- c(0,0,0,0,0,0,1,0,0,0,0,0)
14E12 <- c(0,0,0,0,0,0,0,1,0,0,0,0)
15F48 <- c(0,0,0,0,0,0,0,0,1,0,0,0)
16H12 <- c(0,0,0,0,0,0,0,0,0,1,0,0)
17I10 <- c(0,0,0,0,0,0,0,0,1,0,0,0)
18J02 <- c(0,0,0,0,0,1,0,0,0,0,0,0)
19K52 <- c(0,0,0,0,0,0,1,0,0,0,0,0)
20M01 <- c(0,0,0,1,0,0,0,0,0,0,0,0)
21N34 <- c(0,1,0,0,0,0,0,0,0,0,0,0)
22Z83 <- c(0,0,0,0,0,0,0,0,0,0,1,0)
23
24df <- cbind.data.frame(df,A02,A84,B12,B18,C94,D12,D37,D68,E12,F48,H12,I10,J02,K52,M01,N34,Z83)
25

I've attempted to follow the code here and here but ran into issues that I wasn't sure how to fix. Can anyone point out my mistake/misunderstanding? I would prefer to have a solution in dplyr or base, but really willing to try anything.

Attempts:

1id <- c("1a","2c","3d","4f","5g","6e","7f","8q","9r","10v","11x","12l")
2O <- c(1,1,0,1,1,0,0,1,0,1,0,1)
3dg1 <- c("A02","A84","B12","C94","D37","D12","D68","E12","F48","H12","Z83","")
4dg2 <- c("B18","N34","A02","M01","B12","J02","K52","","I10","","","B18")
5df <- cbind.data.frame(id,O,dg1,dg2)
6A02 <- c(1,0,1,0,0,0,0,0,0,0,0,0)
7A84 <- c(0,1,0,0,0,0,0,0,0,0,0,0)
8B12 <- c(0,0,1,0,1,0,0,0,0,0,0,0)
9B18 <- c(1,0,0,0,0,0,0,0,0,0,0,1)
10C94 <- c(0,0,0,1,0,0,0,0,0,0,0,0)
11D12 <- c(0,0,0,0,0,1,0,0,0,0,0,0)
12D37 <- c(0,0,0,0,1,0,0,0,0,0,0,0)
13D68 <- c(0,0,0,0,0,0,1,0,0,0,0,0)
14E12 <- c(0,0,0,0,0,0,0,1,0,0,0,0)
15F48 <- c(0,0,0,0,0,0,0,0,1,0,0,0)
16H12 <- c(0,0,0,0,0,0,0,0,0,1,0,0)
17I10 <- c(0,0,0,0,0,0,0,0,1,0,0,0)
18J02 <- c(0,0,0,0,0,1,0,0,0,0,0,0)
19K52 <- c(0,0,0,0,0,0,1,0,0,0,0,0)
20M01 <- c(0,0,0,1,0,0,0,0,0,0,0,0)
21N34 <- c(0,1,0,0,0,0,0,0,0,0,0,0)
22Z83 <- c(0,0,0,0,0,0,0,0,0,0,1,0)
23
24df <- cbind.data.frame(df,A02,A84,B12,B18,C94,D12,D37,D68,E12,F48,H12,I10,J02,K52,M01,N34,Z83)
25dumbo <- model.matrix(id ~ dg1+dg2,df)
26
27library(recipes)
28dumber <- df %>% recipe(id ~ .) %>%
29  step_dummy(dg1:dg2,
30             one_hot = TRUE)  %>% 
31  prep() %>% bake(new_data=NULL)
32

ANSWER

Answered 2022-Mar-24 at 05:48
1id <- c("1a","2c","3d","4f","5g","6e","7f","8q","9r","10v","11x","12l")
2O <- c(1,1,0,1,1,0,0,1,0,1,0,1)
3dg1 <- c("A02","A84","B12","C94","D37","D12","D68","E12","F48","H12","Z83","")
4dg2 <- c("B18","N34","A02","M01","B12","J02","K52","","I10","","","B18")
5df <- cbind.data.frame(id,O,dg1,dg2)
6A02 <- c(1,0,1,0,0,0,0,0,0,0,0,0)
7A84 <- c(0,1,0,0,0,0,0,0,0,0,0,0)
8B12 <- c(0,0,1,0,1,0,0,0,0,0,0,0)
9B18 <- c(1,0,0,0,0,0,0,0,0,0,0,1)
10C94 <- c(0,0,0,1,0,0,0,0,0,0,0,0)
11D12 <- c(0,0,0,0,0,1,0,0,0,0,0,0)
12D37 <- c(0,0,0,0,1,0,0,0,0,0,0,0)
13D68 <- c(0,0,0,0,0,0,1,0,0,0,0,0)
14E12 <- c(0,0,0,0,0,0,0,1,0,0,0,0)
15F48 <- c(0,0,0,0,0,0,0,0,1,0,0,0)
16H12 <- c(0,0,0,0,0,0,0,0,0,1,0,0)
17I10 <- c(0,0,0,0,0,0,0,0,1,0,0,0)
18J02 <- c(0,0,0,0,0,1,0,0,0,0,0,0)
19K52 <- c(0,0,0,0,0,0,1,0,0,0,0,0)
20M01 <- c(0,0,0,1,0,0,0,0,0,0,0,0)
21N34 <- c(0,1,0,0,0,0,0,0,0,0,0,0)
22Z83 <- c(0,0,0,0,0,0,0,0,0,0,1,0)
23
24df <- cbind.data.frame(df,A02,A84,B12,B18,C94,D12,D37,D68,E12,F48,H12,I10,J02,K52,M01,N34,Z83)
25dumbo <- model.matrix(id ~ dg1+dg2,df)
26
27library(recipes)
28dumber <- df %>% recipe(id ~ .) %>%
29  step_dummy(dg1:dg2,
30             one_hot = TRUE)  %>% 
31  prep() %>% bake(new_data=NULL)
32library(tidyverse)
33
34
35df %>% 
36  left_join(
37  df %>% 
38    pivot_longer(c(dg1, dg2)) %>% 
39    filter(value != "") %>% 
40    pivot_wider(c(id, O), names_from = value) %>% 
41    mutate(across(c(A02:Z83), ~if_else(is.na(.x), 0, 1)))
42  )
43
44Joining, by = c("id", "O")
45    id O dg1 dg2 A02 B18 A84 N34 B12 C94 M01 D37 D12 J02 D68 K52 E12 F48 I10 H12 Z83
461   1a 1 A02 B18   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
472   2c 1 A84 N34   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0
483   3d 0 B12 A02   1   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
494   4f 1 C94 M01   0   0   0   0   0   1   1   0   0   0   0   0   0   0   0   0   0
505   5g 1 D37 B12   0   0   0   0   1   0   0   1   0   0   0   0   0   0   0   0   0
516   6e 0 D12 J02   0   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0   0
527   7f 0 D68 K52   0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0   0
538   8q 1 E12       0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0
549   9r 0 F48 I10   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   0   0
5510 10v 1 H12       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
5611 11x 0 Z83       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1
5712 12l 1     B18   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
58

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

QUESTION

Conditioning the soup selection on a web scrape.Python/BeautifulSoup

Asked 2022-Mar-21 at 10:00

I have the following code for an item of a list of products:

1    <div class="nice_product_item">
2    <div class="npi_name">
3       <h2>
4           <a href="/solutii-mobile-telefoane-mobile/apple-telefon-mobil-apple-iphone-13-super-retina-xdr-oled-6.1-256gb-flash-camera-duala-12-12-mp-wi-fi-5g-ios-negru-3824456.html"> 
5           <span style="color:red">Stoc limitat!</span>  
6           Telefon Mobil Apple iPhone 13, Super Retina XDR OLED 6.1", 256GB Flash, Camera Duala 12 + 12 MP, Wi-Fi, 5G, iOS (Negru)
7            </a>        
8       </h2>
9    </div>
10
11    <div class="price_block_list">
12        <span class="old_price"> 999,00 Lei </span>
13        <span class="price_discount">-12%</span>
14        <span class="cheaper_by">mai ieftin cu 120,00 lei</span>
15        <span class="real_price">879,00 Lei</span>
16        <span class="evo-credit">evoCREDIT</span></div>
17    </div>
18</div>

Some products got the price_discount span,while others dont

1    <div class="nice_product_item">
2    <div class="npi_name">
3       <h2>
4           <a href="/solutii-mobile-telefoane-mobile/apple-telefon-mobil-apple-iphone-13-super-retina-xdr-oled-6.1-256gb-flash-camera-duala-12-12-mp-wi-fi-5g-ios-negru-3824456.html"> 
5           <span style="color:red">Stoc limitat!</span>  
6           Telefon Mobil Apple iPhone 13, Super Retina XDR OLED 6.1", 256GB Flash, Camera Duala 12 + 12 MP, Wi-Fi, 5G, iOS (Negru)
7            </a>        
8       </h2>
9    </div>
10
11    <div class="price_block_list">
12        <span class="old_price"> 999,00 Lei </span>
13        <span class="price_discount">-12%</span>
14        <span class="cheaper_by">mai ieftin cu 120,00 lei</span>
15        <span class="real_price">879,00 Lei</span>
16        <span class="evo-credit">evoCREDIT</span></div>
17    </div>
18</div><span class="price_discount">-12%</span>
19

I use the following code to scrape the names of products:

1    <div class="nice_product_item">
2    <div class="npi_name">
3       <h2>
4           <a href="/solutii-mobile-telefoane-mobile/apple-telefon-mobil-apple-iphone-13-super-retina-xdr-oled-6.1-256gb-flash-camera-duala-12-12-mp-wi-fi-5g-ios-negru-3824456.html"> 
5           <span style="color:red">Stoc limitat!</span>  
6           Telefon Mobil Apple iPhone 13, Super Retina XDR OLED 6.1", 256GB Flash, Camera Duala 12 + 12 MP, Wi-Fi, 5G, iOS (Negru)
7            </a>        
8       </h2>
9    </div>
10
11    <div class="price_block_list">
12        <span class="old_price"> 999,00 Lei </span>
13        <span class="price_discount">-12%</span>
14        <span class="cheaper_by">mai ieftin cu 120,00 lei</span>
15        <span class="real_price">879,00 Lei</span>
16        <span class="evo-credit">evoCREDIT</span></div>
17    </div>
18</div><span class="price_discount">-12%</span>
19texts = []
20
21for a in soup.select("div.npi_name a[href]"):
22    if a.span:
23        text = a.span.next_sibling
24    else:
25        text = a.string
26    texts.append(text.strip())
27

I don't know what conditions do I need to get the names of the products with discounts.

Note:It has to work for a list

ANSWER

Answered 2022-Mar-21 at 10:00

A way to process the data could be to select all items with discounts:

1    <div class="nice_product_item">
2    <div class="npi_name">
3       <h2>
4           <a href="/solutii-mobile-telefoane-mobile/apple-telefon-mobil-apple-iphone-13-super-retina-xdr-oled-6.1-256gb-flash-camera-duala-12-12-mp-wi-fi-5g-ios-negru-3824456.html"> 
5           <span style="color:red">Stoc limitat!</span>  
6           Telefon Mobil Apple iPhone 13, Super Retina XDR OLED 6.1", 256GB Flash, Camera Duala 12 + 12 MP, Wi-Fi, 5G, iOS (Negru)
7            </a>        
8       </h2>
9    </div>
10
11    <div class="price_block_list">
12        <span class="old_price"> 999,00 Lei </span>
13        <span class="price_discount">-12%</span>
14        <span class="cheaper_by">mai ieftin cu 120,00 lei</span>
15        <span class="real_price">879,00 Lei</span>
16        <span class="evo-credit">evoCREDIT</span></div>
17    </div>
18</div><span class="price_discount">-12%</span>
19texts = []
20
21for a in soup.select("div.npi_name a[href]"):
22    if a.span:
23        text = a.span.next_sibling
24    else:
25        text = a.string
26    texts.append(text.strip())
27soup.select('div.nice_product_item:has(.price_discount):has(a[href])')
28

Iterate over ResultSet, pick information you need and store it in a structured way like list of dicts to process it later e.g. DataFrame and save to csv, json, ...

Example
1    <div class="nice_product_item">
2    <div class="npi_name">
3       <h2>
4           <a href="/solutii-mobile-telefoane-mobile/apple-telefon-mobil-apple-iphone-13-super-retina-xdr-oled-6.1-256gb-flash-camera-duala-12-12-mp-wi-fi-5g-ios-negru-3824456.html"> 
5           <span style="color:red">Stoc limitat!</span>  
6           Telefon Mobil Apple iPhone 13, Super Retina XDR OLED 6.1", 256GB Flash, Camera Duala 12 + 12 MP, Wi-Fi, 5G, iOS (Negru)
7            </a>        
8       </h2>
9    </div>
10
11    <div class="price_block_list">
12        <span class="old_price"> 999,00 Lei </span>
13        <span class="price_discount">-12%</span>
14        <span class="cheaper_by">mai ieftin cu 120,00 lei</span>
15        <span class="real_price">879,00 Lei</span>
16        <span class="evo-credit">evoCREDIT</span></div>
17    </div>
18</div><span class="price_discount">-12%</span>
19texts = []
20
21for a in soup.select("div.npi_name a[href]"):
22    if a.span:
23        text = a.span.next_sibling
24    else:
25        text = a.string
26    texts.append(text.strip())
27soup.select('div.nice_product_item:has(.price_discount):has(a[href])')
28from bs4 import BeautifulSoup
29import pandas as pd
30
31html = '''
32<div class="nice_product_item">
33    <div class="npi_name">
34       <h2>
35           <a href="/solutii-mobile-telefoane-mobile/apple-telefon-mobil-apple-iphone-13-super-retina-xdr-oled-6.1-256gb-flash-camera-duala-12-12-mp-wi-fi-5g-ios-negru-3824456.html"> 
36           <span style="color:red">Stoc limitat!</span>  
37           Telefon Mobil Apple iPhone 13, Super Retina XDR OLED 6.1", 256GB Flash, Camera Duala 12 + 12 MP, Wi-Fi, 5G, iOS (Negru)
38            </a>        
39       </h2>
40    </div>
41
42    <div class="price_block_list">
43        <span class="old_price"> 999,00 Lei </span>
44        <span class="price_discount">-12%</span>
45        <span class="cheaper_by">mai ieftin cu 120,00 lei</span>
46        <span class="real_price">879,00 Lei</span>
47        <span class="evo-credit">evoCREDIT</span></div>
48    </div>
49</div>
50'''
51
52soup = BeautifulSoup(html)
53
54data = []
55
56for e in soup.select('div.nice_product_item:has(.price_discount):has(a[href])'):
57    data.append({
58        'url' : e.a['href'],
59        'label' :s[-1] if (s := list(e.a.stripped_strings)) else None,
60        'price' : s.text if (s := e.select_one('span.real_price')) else None,
61        'discount' : s.text if (s := e.select_one('span.price_discount')) else None,
62        'other' : 'edit for elements you need'
63    })
64pd.DataFrame(data)
65
Output
url label price discount other
/solutii-mobile-telefoane-mobile/apple-telefon-mobil-apple-iphone-13-super-retina-xdr-oled-6.1-256gb-flash-camera-duala-12-12-mp-wi-fi-5g-ios-negru-3824456.html Telefon Mobil Apple iPhone 13, Super Retina XDR OLED 6.1", 256GB Flash, Camera Duala 12 + 12 MP, Wi-Fi, 5G, iOS (Negru) 879,00 Lei -12% edit for elements you need

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

QUESTION

OpenGL Shader Compilation Error Android 12 Samsung Galaxy S21

Asked 2022-Mar-09 at 10:40

I have the following vertex and fragment shaders:

SimpleFragmentShader.fragmentshader:
1#version 300 es
2precision highp float;
3out vec4 FragColor;
4
5uniform vec4 vertexColor;
6
7void main()
8{
9    FragColor = vertexColor;
10}
11
SimpleVertexShader.vertexshader:
1#version 300 es
2precision highp float;
3out vec4 FragColor;
4
5uniform vec4 vertexColor;
6
7void main()
8{
9    FragColor = vertexColor;
10}
11#version 300 es
12layout (location = 0) in vec3 aPos;
13
14uniform mat4 MVP;
15
16void main()
17{
18    gl_Position = MVP * vec4(aPos, 1.0);
19}
20
Function to load the shaders:
1#version 300 es
2precision highp float;
3out vec4 FragColor;
4
5uniform vec4 vertexColor;
6
7void main()
8{
9    FragColor = vertexColor;
10}
11#version 300 es
12layout (location = 0) in vec3 aPos;
13
14uniform mat4 MVP;
15
16void main()
17{
18    gl_Position = MVP * vec4(aPos, 1.0);
19}
20GLuint LoadShaderProgram(const char* vertex_file_path,
21                         const char* fragment_file_path) {
22  // Create the shaders
23  GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
24  GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
25
26  // Read the Vertex Shader code from the file
27  std::string VertexShaderCode;
28  std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
29
30  CHECK(VertexShaderStream.is_open())
31      << "Unable to open shader at " << vertex_file_path;
32
33  std::string Line = "";
34  while (getline(VertexShaderStream, Line)) VertexShaderCode += "\n" + Line;
35  VertexShaderStream.close();
36
37  // Read the Fragment Shader code from the file
38  std::string FragmentShaderCode;
39  std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
40  if (FragmentShaderStream.is_open()) {
41    std::string Line = "";
42    while (getline(FragmentShaderStream, Line))
43      FragmentShaderCode += "\n" + Line;
44    FragmentShaderStream.close();
45  }
46
47  GLint Result = GL_FALSE;
48  int InfoLogLength;
49
50  // Compile Vertex Shader
51  printf("Compiling shader : %s\n", vertex_file_path);
52  char const* VertexSourcePointer = VertexShaderCode.c_str();
53  glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
54  glCompileShader(VertexShaderID);
55
56  // Check Vertex Shader
57  glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
58  glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
59  if (InfoLogLength > 0) {
60    std::vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
61    glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL,
62                       &VertexShaderErrorMessage[0]);
63    printf("%s\n", &VertexShaderErrorMessage[0]);
64  }
65
66  // Compile Fragment Shader
67  printf("Compiling shader : %s\n", fragment_file_path);
68  char const* FragmentSourcePointer = FragmentShaderCode.c_str();
69  glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
70  glCompileShader(FragmentShaderID);
71
72  // Check Fragment Shader
73  glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
74  glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
75  if (InfoLogLength > 0) {
76    std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
77    glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL,
78                       &FragmentShaderErrorMessage[0]);
79    printf("%s\n", &FragmentShaderErrorMessage[0]);
80  }
81
82  // Link the program
83  printf("Linking program\n");
84  GLuint ProgramID = glCreateProgram();
85  glAttachShader(ProgramID, VertexShaderID);
86  glAttachShader(ProgramID, FragmentShaderID);
87  glLinkProgram(ProgramID);
88
89  // Check the program
90  glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
91  glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
92  if (InfoLogLength > 0) {
93    std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
94    glGetProgramInfoLog(ProgramID, InfoLogLength, NULL,
95                        &ProgramErrorMessage[0]);
96    printf("%s\n", &ProgramErrorMessage[0]);
97  }
98
99  glDeleteShader(VertexShaderID);
100  glDeleteShader(FragmentShaderID);
101
102  return ProgramID;
103}
104

build.gradle: targetSdkVersion 31, minSdkVersion 26

When I try to compile the software and run it on my phone (Samsung Galaxy S21 5G, Exynos CPU, Mali-G78 GPU, Android 12), I get the following error:

1#version 300 es
2precision highp float;
3out vec4 FragColor;
4
5uniform vec4 vertexColor;
6
7void main()
8{
9    FragColor = vertexColor;
10}
11#version 300 es
12layout (location = 0) in vec3 aPos;
13
14uniform mat4 MVP;
15
16void main()
17{
18    gl_Position = MVP * vec4(aPos, 1.0);
19}
20GLuint LoadShaderProgram(const char* vertex_file_path,
21                         const char* fragment_file_path) {
22  // Create the shaders
23  GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
24  GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
25
26  // Read the Vertex Shader code from the file
27  std::string VertexShaderCode;
28  std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
29
30  CHECK(VertexShaderStream.is_open())
31      << "Unable to open shader at " << vertex_file_path;
32
33  std::string Line = "";
34  while (getline(VertexShaderStream, Line)) VertexShaderCode += "\n" + Line;
35  VertexShaderStream.close();
36
37  // Read the Fragment Shader code from the file
38  std::string FragmentShaderCode;
39  std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
40  if (FragmentShaderStream.is_open()) {
41    std::string Line = "";
42    while (getline(FragmentShaderStream, Line))
43      FragmentShaderCode += "\n" + Line;
44    FragmentShaderStream.close();
45  }
46
47  GLint Result = GL_FALSE;
48  int InfoLogLength;
49
50  // Compile Vertex Shader
51  printf("Compiling shader : %s\n", vertex_file_path);
52  char const* VertexSourcePointer = VertexShaderCode.c_str();
53  glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
54  glCompileShader(VertexShaderID);
55
56  // Check Vertex Shader
57  glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
58  glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
59  if (InfoLogLength > 0) {
60    std::vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
61    glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL,
62                       &VertexShaderErrorMessage[0]);
63    printf("%s\n", &VertexShaderErrorMessage[0]);
64  }
65
66  // Compile Fragment Shader
67  printf("Compiling shader : %s\n", fragment_file_path);
68  char const* FragmentSourcePointer = FragmentShaderCode.c_str();
69  glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
70  glCompileShader(FragmentShaderID);
71
72  // Check Fragment Shader
73  glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
74  glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
75  if (InfoLogLength > 0) {
76    std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
77    glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL,
78                       &FragmentShaderErrorMessage[0]);
79    printf("%s\n", &FragmentShaderErrorMessage[0]);
80  }
81
82  // Link the program
83  printf("Linking program\n");
84  GLuint ProgramID = glCreateProgram();
85  glAttachShader(ProgramID, VertexShaderID);
86  glAttachShader(ProgramID, FragmentShaderID);
87  glLinkProgram(ProgramID);
88
89  // Check the program
90  glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
91  glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
92  if (InfoLogLength > 0) {
93    std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
94    glGetProgramInfoLog(ProgramID, InfoLogLength, NULL,
95                        &ProgramErrorMessage[0]);
96    printf("%s\n", &ProgramErrorMessage[0]);
97  }
98
99  glDeleteShader(VertexShaderID);
100  glDeleteShader(FragmentShaderID);
101
102  return ProgramID;
103}
104D/native: Compiling shader : /data/user/0/app/files/shaders/SimpleVertexShader.vertexshader
105D/native: 0:2: P0005: #version must be on the first line in a program and only whitespace are allowed in the declaration
106    Compiling shader
107D/native:  : /data/user/0/app/files/shaders/SimpleFragmentShader.fragmentshader
108D/native: 0:2: P0005: #version must be on the first line in a program and only whitespace are allowed in the declaration
109    Linking program
110D/native: Link failed because of invalid vertex shader.
111

However, when I try to run the same code on a Samsung Galaxy Tab S7 (SM-T870, Snapdragon 865+) running Android 12, it works.

The error message hints at a syntax error, however I do not think that this is the issue since the software compiles fine on the Galaxy Tab S7.

I have tried different versions (#version 100/200/300 es/310 es/320 es) with the Samsung Galaxy S21 phone, but the code only compiled when using #version 100. However, the official ARM-Homepage states that the Galaxy S21 Mali-G78 GPU should support all these versions.

What can be causing this problem? Are there any Graphics Drivers that lack OpenGL support on Exynos Versions of Samsung Devices compared to their Snapdragon counterparts? I did not find related issues using Google or StackOverflow. The only other issue with OpenGL and Android 12 on Samsung Devices I found (here and here) were involving Emulators, which is not the case in my application.

Thank you for your help!

ANSWER

Answered 2022-Mar-09 at 10:40

As mentioned in the comment, the code...

1#version 300 es
2precision highp float;
3out vec4 FragColor;
4
5uniform vec4 vertexColor;
6
7void main()
8{
9    FragColor = vertexColor;
10}
11#version 300 es
12layout (location = 0) in vec3 aPos;
13
14uniform mat4 MVP;
15
16void main()
17{
18    gl_Position = MVP * vec4(aPos, 1.0);
19}
20GLuint LoadShaderProgram(const char* vertex_file_path,
21                         const char* fragment_file_path) {
22  // Create the shaders
23  GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
24  GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
25
26  // Read the Vertex Shader code from the file
27  std::string VertexShaderCode;
28  std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
29
30  CHECK(VertexShaderStream.is_open())
31      << "Unable to open shader at " << vertex_file_path;
32
33  std::string Line = "";
34  while (getline(VertexShaderStream, Line)) VertexShaderCode += "\n" + Line;
35  VertexShaderStream.close();
36
37  // Read the Fragment Shader code from the file
38  std::string FragmentShaderCode;
39  std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
40  if (FragmentShaderStream.is_open()) {
41    std::string Line = "";
42    while (getline(FragmentShaderStream, Line))
43      FragmentShaderCode += "\n" + Line;
44    FragmentShaderStream.close();
45  }
46
47  GLint Result = GL_FALSE;
48  int InfoLogLength;
49
50  // Compile Vertex Shader
51  printf("Compiling shader : %s\n", vertex_file_path);
52  char const* VertexSourcePointer = VertexShaderCode.c_str();
53  glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
54  glCompileShader(VertexShaderID);
55
56  // Check Vertex Shader
57  glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
58  glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
59  if (InfoLogLength > 0) {
60    std::vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
61    glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL,
62                       &VertexShaderErrorMessage[0]);
63    printf("%s\n", &VertexShaderErrorMessage[0]);
64  }
65
66  // Compile Fragment Shader
67  printf("Compiling shader : %s\n", fragment_file_path);
68  char const* FragmentSourcePointer = FragmentShaderCode.c_str();
69  glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
70  glCompileShader(FragmentShaderID);
71
72  // Check Fragment Shader
73  glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
74  glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
75  if (InfoLogLength > 0) {
76    std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
77    glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL,
78                       &FragmentShaderErrorMessage[0]);
79    printf("%s\n", &FragmentShaderErrorMessage[0]);
80  }
81
82  // Link the program
83  printf("Linking program\n");
84  GLuint ProgramID = glCreateProgram();
85  glAttachShader(ProgramID, VertexShaderID);
86  glAttachShader(ProgramID, FragmentShaderID);
87  glLinkProgram(ProgramID);
88
89  // Check the program
90  glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
91  glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
92  if (InfoLogLength > 0) {
93    std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
94    glGetProgramInfoLog(ProgramID, InfoLogLength, NULL,
95                        &ProgramErrorMessage[0]);
96    printf("%s\n", &ProgramErrorMessage[0]);
97  }
98
99  glDeleteShader(VertexShaderID);
100  glDeleteShader(FragmentShaderID);
101
102  return ProgramID;
103}
104D/native: Compiling shader : /data/user/0/app/files/shaders/SimpleVertexShader.vertexshader
105D/native: 0:2: P0005: #version must be on the first line in a program and only whitespace are allowed in the declaration
106    Compiling shader
107D/native:  : /data/user/0/app/files/shaders/SimpleFragmentShader.fragmentshader
108D/native: 0:2: P0005: #version must be on the first line in a program and only whitespace are allowed in the declaration
109    Linking program
110D/native: Link failed because of invalid vertex shader.
111std::string Line = "";
112while (getline(VertexShaderStream, Line))
113    VertexShaderCode += "\n" + Line;
114

adds a blank line at the beginning of the shader source VertexShaderCode. Hence the error message regarding the missing or misplaced version specifier. Just change the code to...

1#version 300 es
2precision highp float;
3out vec4 FragColor;
4
5uniform vec4 vertexColor;
6
7void main()
8{
9    FragColor = vertexColor;
10}
11#version 300 es
12layout (location = 0) in vec3 aPos;
13
14uniform mat4 MVP;
15
16void main()
17{
18    gl_Position = MVP * vec4(aPos, 1.0);
19}
20GLuint LoadShaderProgram(const char* vertex_file_path,
21                         const char* fragment_file_path) {
22  // Create the shaders
23  GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
24  GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
25
26  // Read the Vertex Shader code from the file
27  std::string VertexShaderCode;
28  std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
29
30  CHECK(VertexShaderStream.is_open())
31      << "Unable to open shader at " << vertex_file_path;
32
33  std::string Line = "";
34  while (getline(VertexShaderStream, Line)) VertexShaderCode += "\n" + Line;
35  VertexShaderStream.close();
36
37  // Read the Fragment Shader code from the file
38  std::string FragmentShaderCode;
39  std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
40  if (FragmentShaderStream.is_open()) {
41    std::string Line = "";
42    while (getline(FragmentShaderStream, Line))
43      FragmentShaderCode += "\n" + Line;
44    FragmentShaderStream.close();
45  }
46
47  GLint Result = GL_FALSE;
48  int InfoLogLength;
49
50  // Compile Vertex Shader
51  printf("Compiling shader : %s\n", vertex_file_path);
52  char const* VertexSourcePointer = VertexShaderCode.c_str();
53  glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
54  glCompileShader(VertexShaderID);
55
56  // Check Vertex Shader
57  glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
58  glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
59  if (InfoLogLength > 0) {
60    std::vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
61    glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL,
62                       &VertexShaderErrorMessage[0]);
63    printf("%s\n", &VertexShaderErrorMessage[0]);
64  }
65
66  // Compile Fragment Shader
67  printf("Compiling shader : %s\n", fragment_file_path);
68  char const* FragmentSourcePointer = FragmentShaderCode.c_str();
69  glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
70  glCompileShader(FragmentShaderID);
71
72  // Check Fragment Shader
73  glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
74  glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
75  if (InfoLogLength > 0) {
76    std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
77    glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL,
78                       &FragmentShaderErrorMessage[0]);
79    printf("%s\n", &FragmentShaderErrorMessage[0]);
80  }
81
82  // Link the program
83  printf("Linking program\n");
84  GLuint ProgramID = glCreateProgram();
85  glAttachShader(ProgramID, VertexShaderID);
86  glAttachShader(ProgramID, FragmentShaderID);
87  glLinkProgram(ProgramID);
88
89  // Check the program
90  glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
91  glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
92  if (InfoLogLength > 0) {
93    std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
94    glGetProgramInfoLog(ProgramID, InfoLogLength, NULL,
95                        &ProgramErrorMessage[0]);
96    printf("%s\n", &ProgramErrorMessage[0]);
97  }
98
99  glDeleteShader(VertexShaderID);
100  glDeleteShader(FragmentShaderID);
101
102  return ProgramID;
103}
104D/native: Compiling shader : /data/user/0/app/files/shaders/SimpleVertexShader.vertexshader
105D/native: 0:2: P0005: #version must be on the first line in a program and only whitespace are allowed in the declaration
106    Compiling shader
107D/native:  : /data/user/0/app/files/shaders/SimpleFragmentShader.fragmentshader
108D/native: 0:2: P0005: #version must be on the first line in a program and only whitespace are allowed in the declaration
109    Linking program
110D/native: Link failed because of invalid vertex shader.
111std::string Line = "";
112while (getline(VertexShaderStream, Line))
113    VertexShaderCode += "\n" + Line;
114std::string Line = "";
115while (getline(VertexShaderStream, Line))
116    VertexShaderCode += Line + "\n";
117

and do similarly for the fragment shader code section.

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

QUESTION

Mongodb: How to pass another stage inside $group?

Asked 2022-Mar-05 at 02:01


Expected Output:

1[
2  {
3    "_id": "healty",
4    "doc_count": 2,
5    "ingredients": {
6      "Leaves": {
7        "1.2g": 1,
8        "1.5g": 1
9      },
10      "Spinach": {
11        "12g": 1,
12        "18g": 1
13      }
14    }
15  },
16  {
17    "_id": "junk",
18    "doc_count": 3,
19    "ingredients": {
20      "cheese": {
21        "100g": 1,
22        "120g": 2
23      },
24      "meat": {
25        "50g": 1,
26        "60g": 1,
27        "70g": 1
28      }
29    }
30  }
31]
32

Aggregation Below: Playground1

1[
2  {
3    "_id": "healty",
4    "doc_count": 2,
5    "ingredients": {
6      "Leaves": {
7        "1.2g": 1,
8        "1.5g": 1
9      },
10      "Spinach": {
11        "12g": 1,
12        "18g": 1
13      }
14    }
15  },
16  {
17    "_id": "junk",
18    "doc_count": 3,
19    "ingredients": {
20      "cheese": {
21        "100g": 1,
22        "120g": 2
23      },
24      "meat": {
25        "50g": 1,
26        "60g": 1,
27        "70g": 1
28      }
29    }
30  }
31]
32db.collection.aggregate([
33  {
34    $group: {       
35      "_id": "$type",  // grouping the document by "type" field
36      "ingredients": {
37        $push: "$$ROOT"  //want to run Playground2 aggrgtion in each of it
38      },
39      "doc_count": {
40        $sum: 1        // total count
41      }
42    }
43  }
44])
45


After that,

I've also figured out an Another Step to convert the ingredients array after it: Playground2

But, this aggregation is for All the documents. I want to make Playground2 aggregation work for the ingredients field only in each group Object.

It's similar to combining Playground1 & Playground2. How do I do this?

ANSWER

Answered 2022-Feb-25 at 06:03
1[
2  {
3    "_id": "healty",
4    "doc_count": 2,
5    "ingredients": {
6      "Leaves": {
7        "1.2g": 1,
8        "1.5g": 1
9      },
10      "Spinach": {
11        "12g": 1,
12        "18g": 1
13      }
14    }
15  },
16  {
17    "_id": "junk",
18    "doc_count": 3,
19    "ingredients": {
20      "cheese": {
21        "100g": 1,
22        "120g": 2
23      },
24      "meat": {
25        "50g": 1,
26        "60g": 1,
27        "70g": 1
28      }
29    }
30  }
31]
32db.collection.aggregate([
33  {
34    $group: {       
35      "_id": "$type",  // grouping the document by "type" field
36      "ingredients": {
37        $push: "$$ROOT"  //want to run Playground2 aggrgtion in each of it
38      },
39      "doc_count": {
40        $sum: 1        // total count
41      }
42    }
43  }
44])
45db.collection.aggregate([
46  {
47    "$set": {
48      "ingredients": {
49        "$objectToArray": "$ingredients"
50      }
51    }
52  },
53  {
54    "$unwind": "$ingredients"
55  },
56  {
57    "$group": {
58      "_id": {
59        type: "$type",
60        ingredient: "$ingredients"
61      },
62      "count": {
63        "$sum": 1
64      },
65      "doc_count": {
66        "$addToSet": "$item"
67      }
68    }
69  },
70  {
71    "$group": {
72      "_id": {
73        type: "$_id.type",
74        ingredient: "$_id.ingredient.k"
75      },
76      "docs": {
77        "$push": {
78          k: "$_id.ingredient.v",
79          v: "$count"
80        }
81      },
82      "doc_count": {
83        "$push": "$doc_count"
84      }
85    }
86  },
87  {
88    "$group": {
89      "_id": "$_id.type",
90      "ingredients": {
91        "$push": {
92          k: "$_id.ingredient",
93          v: {
94            "$arrayToObject": "$docs"
95          }
96        }
97      },
98      "doc_count": {
99        "$push": {
100          $reduce: {
101            input: "$doc_count",
102            initialValue: [],
103            in: {
104              $concatArrays: [
105                "$$value",
106                "$$this"
107              ]
108            }
109          }
110        }
111      }
112    }
113  },
114  {
115    "$set": {
116      "ingredients": {
117        "$arrayToObject": "$ingredients"
118      },
119      doc_count: {
120        "$size": {
121          "$setUnion": {
122            $reduce: {
123              input: "$doc_count",
124              initialValue: [],
125              in: {
126                $concatArrays: [
127                  "$$value",
128                  "$$this"
129                ]
130              }
131            }
132          }
133        }
134      }
135    }
136  }
137])
138

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

QUESTION

Combine duplicate tokens inside huge JSON file into nested array of objects using React

Asked 2022-Feb-18 at 20:36

I looked at several of the suggested solutions but none seemed to rise to this confounding data formatting challenge.

I have a huge JSON file (over 100k rows) and massive duplicates of data all as top level objects. Here's an example:

1[
2   {
3      "manufacturer":"Samsung",
4      "device":"Galaxy A32 5G",
5      "model":"SM-A326B",
6      "chipset":"Mediatek MT6853V/NZA",
7      "date":"2022-01-01",
8      "fw_id":"A326BXXS4AVA1",
9      "android":"R(Android 11)",
10      "known_passcode":false,
11      "afu":false,
12      "bfu":false,
13      "bruteforce":false
14   },
15   {
16      "manufacturer":"Samsung",
17      "device":"Galaxy A32 5G",
18      "model":"SM-A326U",
19      "chipset":"Mediatek MT6853V/NZA",
20      "date":"2021-03-01",
21      "fw_id":"A326USQU1AUD4",
22      "android":"R(Android 11)",
23      "known_passcode":true,
24      "afu":false,
25      "bfu":true,
26      "bruteforce":true
27   },
28   {
29      "manufacturer":"Samsung",
30      "device":"Galaxy A32 5G",
31      "model":"SM-A326U1",
32      "chipset":"Mediatek MT6853V/NZA",
33      "date":"2021-09-01",
34      "fw_id":"A326U1UEU5AUJ2",
35      "android":"R(Android 11)",
36      "known_passcode":true,
37      "afu":false,
38      "bfu":true,
39      "bruteforce":true
40   },
41   {
42      "manufacturer":"LGE",
43      "device":"LG K31",
44      "model":"LGL355DL",
45      "chipset":"Mediatek MT6762",
46      "date":"unknown",
47      "fw_id":"L355DL10l",
48      "android":"unknown",
49      "known_passcode":false,
50      "afu":false,
51      "bfu":false,
52      "bruteforce":false
53   }
54]
55
56

This needs to be organized so that data points like manufacturer, device, model are not duplicated hundreds of times.

Btw, here's a JSFiddle to play with: https://jsfiddle.net/xpancom/Lq7duahv/

Ideally, the JSON format would be the following:

1[
2   {
3      "manufacturer":"Samsung",
4      "device":"Galaxy A32 5G",
5      "model":"SM-A326B",
6      "chipset":"Mediatek MT6853V/NZA",
7      "date":"2022-01-01",
8      "fw_id":"A326BXXS4AVA1",
9      "android":"R(Android 11)",
10      "known_passcode":false,
11      "afu":false,
12      "bfu":false,
13      "bruteforce":false
14   },
15   {
16      "manufacturer":"Samsung",
17      "device":"Galaxy A32 5G",
18      "model":"SM-A326U",
19      "chipset":"Mediatek MT6853V/NZA",
20      "date":"2021-03-01",
21      "fw_id":"A326USQU1AUD4",
22      "android":"R(Android 11)",
23      "known_passcode":true,
24      "afu":false,
25      "bfu":true,
26      "bruteforce":true
27   },
28   {
29      "manufacturer":"Samsung",
30      "device":"Galaxy A32 5G",
31      "model":"SM-A326U1",
32      "chipset":"Mediatek MT6853V/NZA",
33      "date":"2021-09-01",
34      "fw_id":"A326U1UEU5AUJ2",
35      "android":"R(Android 11)",
36      "known_passcode":true,
37      "afu":false,
38      "bfu":true,
39      "bruteforce":true
40   },
41   {
42      "manufacturer":"LGE",
43      "device":"LG K31",
44      "model":"LGL355DL",
45      "chipset":"Mediatek MT6762",
46      "date":"unknown",
47      "fw_id":"L355DL10l",
48      "android":"unknown",
49      "known_passcode":false,
50      "afu":false,
51      "bfu":false,
52      "bruteforce":false
53   }
54]
55
56[
57  {
58    "manufacturers": [
59      {
60        "manufacturer": "Samsung",
61        "devices": [
62          {
63            "device": "Galaxy A32 5G",
64            "models": [
65              {
66                "model": "SM-A326B",
67                "data": [
68                  {
69                    "chipset": "Mediatek MT6853V/NZA",
70                    "date": "2022-01-01",
71                    "fw_id": "A326BXXS4AVA1",
72                    "android": "R(Android 11)",
73                    "known_passcode": false,
74                    "afu": false,
75                    "bfu": false,
76                    "bruteforce": false
77                  },
78                  {
79                    "chipset": "Mediatek MT6853V/NZA",
80                    "date": "2021-09-01",
81                    "fw_id": "A326BXXU3AUH7",
82                    "android": "R(Android 11)",
83                    "known_passcode": true,
84                    "afu": false,
85                    "bfu": true,
86                    "bruteforce": true
87                  }
88                ]
89              },
90              {
91                "model": "SM-A326U1",
92                "data": [
93                  {
94                    "chipset": "Mediatek MT6853V/NZA",
95                    "date": "2021-09-01",
96                    "fw_id": "A326U1UEU5AUJ2",
97                    "android": "R(Android 11)",
98                    "known_passcode": true,
99                    "afu": false,
100                    "bfu": true,
101                    "bruteforce": true
102                  }
103                ]
104              }
105            ]
106          }
107        ]
108      },
109      {
110        "manufacturer": "LGE",
111        "devices": [
112          {
113            "device": "LG K31",
114            "models": [
115              {
116                "model": "SM-A326B",
117                "data": [
118                  {
119                    "chipset": "Mediatek MT6762",
120                    "date": "unknown",
121                    "fw_id": "L355DL10l",
122                    "android": "unknown",
123                    "known_passcode": false,
124                    "afu": false,
125                    "bfu": false,
126                    "bruteforce": false
127                  }
128                ]
129              }
130            ]
131          }
132        ]
133      }
134    ]
135  }
136]
137
138

Working in React, here's what I've got so far in trying to massage this data:

1[
2   {
3      "manufacturer":"Samsung",
4      "device":"Galaxy A32 5G",
5      "model":"SM-A326B",
6      "chipset":"Mediatek MT6853V/NZA",
7      "date":"2022-01-01",
8      "fw_id":"A326BXXS4AVA1",
9      "android":"R(Android 11)",
10      "known_passcode":false,
11      "afu":false,
12      "bfu":false,
13      "bruteforce":false
14   },
15   {
16      "manufacturer":"Samsung",
17      "device":"Galaxy A32 5G",
18      "model":"SM-A326U",
19      "chipset":"Mediatek MT6853V/NZA",
20      "date":"2021-03-01",
21      "fw_id":"A326USQU1AUD4",
22      "android":"R(Android 11)",
23      "known_passcode":true,
24      "afu":false,
25      "bfu":true,
26      "bruteforce":true
27   },
28   {
29      "manufacturer":"Samsung",
30      "device":"Galaxy A32 5G",
31      "model":"SM-A326U1",
32      "chipset":"Mediatek MT6853V/NZA",
33      "date":"2021-09-01",
34      "fw_id":"A326U1UEU5AUJ2",
35      "android":"R(Android 11)",
36      "known_passcode":true,
37      "afu":false,
38      "bfu":true,
39      "bruteforce":true
40   },
41   {
42      "manufacturer":"LGE",
43      "device":"LG K31",
44      "model":"LGL355DL",
45      "chipset":"Mediatek MT6762",
46      "date":"unknown",
47      "fw_id":"L355DL10l",
48      "android":"unknown",
49      "known_passcode":false,
50      "afu":false,
51      "bfu":false,
52      "bruteforce":false
53   }
54]
55
56[
57  {
58    "manufacturers": [
59      {
60        "manufacturer": "Samsung",
61        "devices": [
62          {
63            "device": "Galaxy A32 5G",
64            "models": [
65              {
66                "model": "SM-A326B",
67                "data": [
68                  {
69                    "chipset": "Mediatek MT6853V/NZA",
70                    "date": "2022-01-01",
71                    "fw_id": "A326BXXS4AVA1",
72                    "android": "R(Android 11)",
73                    "known_passcode": false,
74                    "afu": false,
75                    "bfu": false,
76                    "bruteforce": false
77                  },
78                  {
79                    "chipset": "Mediatek MT6853V/NZA",
80                    "date": "2021-09-01",
81                    "fw_id": "A326BXXU3AUH7",
82                    "android": "R(Android 11)",
83                    "known_passcode": true,
84                    "afu": false,
85                    "bfu": true,
86                    "bruteforce": true
87                  }
88                ]
89              },
90              {
91                "model": "SM-A326U1",
92                "data": [
93                  {
94                    "chipset": "Mediatek MT6853V/NZA",
95                    "date": "2021-09-01",
96                    "fw_id": "A326U1UEU5AUJ2",
97                    "android": "R(Android 11)",
98                    "known_passcode": true,
99                    "afu": false,
100                    "bfu": true,
101                    "bruteforce": true
102                  }
103                ]
104              }
105            ]
106          }
107        ]
108      },
109      {
110        "manufacturer": "LGE",
111        "devices": [
112          {
113            "device": "LG K31",
114            "models": [
115              {
116                "model": "SM-A326B",
117                "data": [
118                  {
119                    "chipset": "Mediatek MT6762",
120                    "date": "unknown",
121                    "fw_id": "L355DL10l",
122                    "android": "unknown",
123                    "known_passcode": false,
124                    "afu": false,
125                    "bfu": false,
126                    "bruteforce": false
127                  }
128                ]
129              }
130            ]
131          }
132        ]
133      }
134    ]
135  }
136]
137
138  const source = data;
139  const destination = [];
140  const classifiedTokens = []; // will be used to stored already classified tokens
141  const classifiedTokensModel = []; // will be used to stored already classified tokens for models
142
143  const getNextTokenArray = (source) => {
144    let unusedToken = null;
145    const nextTokenArray = source.filter(function (element) {
146      if (!unusedToken && !classifiedTokens.includes(element['device'])) {
147        unusedToken = element['device'];
148        classifiedTokens.push(unusedToken);
149      }
150      return unusedToken ? unusedToken === element['device'] : false;
151    });
152    return unusedToken ? nextTokenArray : null;
153  };
154
155  // Pass in arrays deconstructed from addToDestination to process third tier nested objects for models
156  const getNextTokenArrayModel = (tokenObject) => {
157    let tokenObjectDevice = tokenObject['device'];
158    let tokenObjectData = tokenObject['data'];
159    let unusedTokenModel = null;
160    const nextTokenArrayModel = tokenObjectData.filter(function (element) {
161      if (!unusedTokenModel && !classifiedTokensModel.includes(element['model'])) {
162        unusedTokenModel = element['model'];
163        classifiedTokensModel.push(unusedTokenModel);
164      }
165      return unusedTokenModel ? unusedTokenModel === element['model'] : false;
166    });
167    //return unusedTokenModel ? nextTokenArrayModel : null;
168
169    if (unusedTokenModel) {
170      if (nextTokenArrayModel.length === 0) return;
171      let res = {
172        device: tokenObjectDevice,
173        model: nextTokenArrayModel[0]['model'],
174        data: [],
175      };
176      nextTokenArrayModel.forEach((element) => {
177        res.data.push({
178          manufacturer: element.manufacturer,
179          chipset: element.chipset,
180          date: element.date,
181          fw_id: element.fw_id,
182          android: element.android,
183          knownPasscode: element.knownPasscode,
184          afu: element.afu,
185          bfu: element.bfu,
186          bruteforce: element.bruteforce,
187        });
188      });
189      destination.push(res);
190    } else {
191      return null;
192    }
193    
194  };
195
196  const addToDestination = (tokenArray) => {
197    if (tokenArray.length === 0) return;
198    let res = {
199      device: tokenArray[0]['device'],
200      data: [],
201    };
202    tokenArray.forEach((element) => {
203      res.data.push({
204        manufacturer: element.manufacturer,
205        model: element.model,
206        chipset: element.chipset,
207        date: element.date,
208        fw_id: element.fw_id,
209        android: element.android,
210        knownPasscode: element.knownPasscode,
211        afu: element.afu,
212        bfu: element.bfu,
213        bruteforce: element.bruteforce,
214      });
215    });
216
217    getNextTokenArrayModel(res); // Call this to process and group nested model duplicates by device
218
219    //destination.push(res);
220  };
221
222  let nextTokenArray = getNextTokenArray(source);
223
224  while (nextTokenArray) {
225    addToDestination(nextTokenArray);
226    nextTokenArray = getNextTokenArray(source);
227  }
228
229  setTimeout(() => {
230    document.getElementById('root').innerHTML =
231      '<pre>' + JSON.stringify(destination, null, 2) + '</pre>';
232  }, 1000);
233
234};
235
236
237

And here's the JSFiddle again: https://jsfiddle.net/xpancom/Lq7duahv/

Who can smash this data formatting dilemma?

ANSWER

Answered 2022-Feb-18 at 20:36

This answer is not React specific, but one approach would be to use array.reduce() to transform each level/node of the structure as shown in the code snippet below.

1[
2   {
3      "manufacturer":"Samsung",
4      "device":"Galaxy A32 5G",
5      "model":"SM-A326B",
6      "chipset":"Mediatek MT6853V/NZA",
7      "date":"2022-01-01",
8      "fw_id":"A326BXXS4AVA1",
9      "android":"R(Android 11)",
10      "known_passcode":false,
11      "afu":false,
12      "bfu":false,
13      "bruteforce":false
14   },
15   {
16      "manufacturer":"Samsung",
17      "device":"Galaxy A32 5G",
18      "model":"SM-A326U",
19      "chipset":"Mediatek MT6853V/NZA",
20      "date":"2021-03-01",
21      "fw_id":"A326USQU1AUD4",
22      "android":"R(Android 11)",
23      "known_passcode":true,
24      "afu":false,
25      "bfu":true,
26      "bruteforce":true
27   },
28   {
29      "manufacturer":"Samsung",
30      "device":"Galaxy A32 5G",
31      "model":"SM-A326U1",
32      "chipset":"Mediatek MT6853V/NZA",
33      "date":"2021-09-01",
34      "fw_id":"A326U1UEU5AUJ2",
35      "android":"R(Android 11)",
36      "known_passcode":true,
37      "afu":false,
38      "bfu":true,
39      "bruteforce":true
40   },
41   {
42      "manufacturer":"LGE",
43      "device":"LG K31",
44      "model":"LGL355DL",
45      "chipset":"Mediatek MT6762",
46      "date":"unknown",
47      "fw_id":"L355DL10l",
48      "android":"unknown",
49      "known_passcode":false,
50      "afu":false,
51      "bfu":false,
52      "bruteforce":false
53   }
54]
55
56[
57  {
58    "manufacturers": [
59      {
60        "manufacturer": "Samsung",
61        "devices": [
62          {
63            "device": "Galaxy A32 5G",
64            "models": [
65              {
66                "model": "SM-A326B",
67                "data": [
68                  {
69                    "chipset": "Mediatek MT6853V/NZA",
70                    "date": "2022-01-01",
71                    "fw_id": "A326BXXS4AVA1",
72                    "android": "R(Android 11)",
73                    "known_passcode": false,
74                    "afu": false,
75                    "bfu": false,
76                    "bruteforce": false
77                  },
78                  {
79                    "chipset": "Mediatek MT6853V/NZA",
80                    "date": "2021-09-01",
81                    "fw_id": "A326BXXU3AUH7",
82                    "android": "R(Android 11)",
83                    "known_passcode": true,
84                    "afu": false,
85                    "bfu": true,
86                    "bruteforce": true
87                  }
88                ]
89              },
90              {
91                "model": "SM-A326U1",
92                "data": [
93                  {
94                    "chipset": "Mediatek MT6853V/NZA",
95                    "date": "2021-09-01",
96                    "fw_id": "A326U1UEU5AUJ2",
97                    "android": "R(Android 11)",
98                    "known_passcode": true,
99                    "afu": false,
100                    "bfu": true,
101                    "bruteforce": true
102                  }
103                ]
104              }
105            ]
106          }
107        ]
108      },
109      {
110        "manufacturer": "LGE",
111        "devices": [
112          {
113            "device": "LG K31",
114            "models": [
115              {
116                "model": "SM-A326B",
117                "data": [
118                  {
119                    "chipset": "Mediatek MT6762",
120                    "date": "unknown",
121                    "fw_id": "L355DL10l",
122                    "android": "unknown",
123                    "known_passcode": false,
124                    "afu": false,
125                    "bfu": false,
126                    "bruteforce": false
127                  }
128                ]
129              }
130            ]
131          }
132        ]
133      }
134    ]
135  }
136]
137
138  const source = data;
139  const destination = [];
140  const classifiedTokens = []; // will be used to stored already classified tokens
141  const classifiedTokensModel = []; // will be used to stored already classified tokens for models
142
143  const getNextTokenArray = (source) => {
144    let unusedToken = null;
145    const nextTokenArray = source.filter(function (element) {
146      if (!unusedToken && !classifiedTokens.includes(element['device'])) {
147        unusedToken = element['device'];
148        classifiedTokens.push(unusedToken);
149      }
150      return unusedToken ? unusedToken === element['device'] : false;
151    });
152    return unusedToken ? nextTokenArray : null;
153  };
154
155  // Pass in arrays deconstructed from addToDestination to process third tier nested objects for models
156  const getNextTokenArrayModel = (tokenObject) => {
157    let tokenObjectDevice = tokenObject['device'];
158    let tokenObjectData = tokenObject['data'];
159    let unusedTokenModel = null;
160    const nextTokenArrayModel = tokenObjectData.filter(function (element) {
161      if (!unusedTokenModel && !classifiedTokensModel.includes(element['model'])) {
162        unusedTokenModel = element['model'];
163        classifiedTokensModel.push(unusedTokenModel);
164      }
165      return unusedTokenModel ? unusedTokenModel === element['model'] : false;
166    });
167    //return unusedTokenModel ? nextTokenArrayModel : null;
168
169    if (unusedTokenModel) {
170      if (nextTokenArrayModel.length === 0) return;
171      let res = {
172        device: tokenObjectDevice,
173        model: nextTokenArrayModel[0]['model'],
174        data: [],
175      };
176      nextTokenArrayModel.forEach((element) => {
177        res.data.push({
178          manufacturer: element.manufacturer,
179          chipset: element.chipset,
180          date: element.date,
181          fw_id: element.fw_id,
182          android: element.android,
183          knownPasscode: element.knownPasscode,
184          afu: element.afu,
185          bfu: element.bfu,
186          bruteforce: element.bruteforce,
187        });
188      });
189      destination.push(res);
190    } else {
191      return null;
192    }
193    
194  };
195
196  const addToDestination = (tokenArray) => {
197    if (tokenArray.length === 0) return;
198    let res = {
199      device: tokenArray[0]['device'],
200      data: [],
201    };
202    tokenArray.forEach((element) => {
203      res.data.push({
204        manufacturer: element.manufacturer,
205        model: element.model,
206        chipset: element.chipset,
207        date: element.date,
208        fw_id: element.fw_id,
209        android: element.android,
210        knownPasscode: element.knownPasscode,
211        afu: element.afu,
212        bfu: element.bfu,
213        bruteforce: element.bruteforce,
214      });
215    });
216
217    getNextTokenArrayModel(res); // Call this to process and group nested model duplicates by device
218
219    //destination.push(res);
220  };
221
222  let nextTokenArray = getNextTokenArray(source);
223
224  while (nextTokenArray) {
225    addToDestination(nextTokenArray);
226    nextTokenArray = getNextTokenArray(source);
227  }
228
229  setTimeout(() => {
230    document.getElementById('root').innerHTML =
231      '<pre>' + JSON.stringify(destination, null, 2) + '</pre>';
232  }, 1000);
233
234};
235
236
237const source = [
238  {
239    manufacturer: 'Samsung',
240    device: 'Galaxy A32 5G',
241    model: 'SM-A326B',
242    chipset: 'Mediatek MT6853V/NZA',
243    date: '2022-01-01',
244    fw_id: 'A326BXXS4AVA1',
245    android: 'R(Android 11)',
246    known_passcode: false,
247    afu: false,
248    bfu: false,
249    bruteforce: false,
250  },
251  {
252    manufacturer: 'Samsung',
253    device: 'Galaxy A32 5G',
254    model: 'SM-A326B',
255    chipset: 'Mediatek MT6853V/NZA',
256    date: '2022-01-01',
257    fw_id: 'A326BXXS4AVA1',
258    android: 'R(Android 11)',
259    known_passcode: false,
260    afu: false,
261    bfu: false,
262    bruteforce: false,
263  },
264  {
265    manufacturer: 'Samsung',
266    device: 'Galaxy A32 5G',
267    model: 'SM-A326U',
268    chipset: 'Mediatek MT6853V/NZA',
269    date: '2021-03-01',
270    fw_id: 'A326USQU1AUD4',
271    android: 'R(Android 11)',
272    known_passcode: true,
273    afu: false,
274    bfu: true,
275    bruteforce: true,
276  },
277  {
278    manufacturer: 'Samsung',
279    device: 'Galaxy A32 5G',
280    model: 'SM-A326U1',
281    chipset: 'Mediatek MT6853V/NZA',
282    date: '2021-09-01',
283    fw_id: 'A326U1UEU5AUJ2',
284    android: 'R(Android 11)',
285    known_passcode: true,
286    afu: false,
287    bfu: true,
288    bruteforce: true,
289  },
290  {
291    manufacturer: 'LGE',
292    device: 'LG K31',
293    model: 'LGL355DL',
294    chipset: 'Mediatek MT6762',
295    date: 'unknown',
296    fw_id: 'L355DL10l',
297    android: 'unknown',
298    known_passcode: false,
299    afu: false,
300    bfu: false,
301    bruteforce: false,
302  },
303];
304
305function generateTree(data, key) {
306  return data.reduce((acc, val) => {
307    // Split the key name from the child data
308    const { [key.name]: keyName, ...childData } = val;
309
310    // Find a tree item in the structure being generated
311    const treeItem = acc.find((item) => item[key.name] === keyName);
312
313    if (treeItem) {
314      // If found, append child data
315      treeItem[key.child].push(childData);
316    } else {
317      // If not found, create new key and append child data
318      acc.push({ [key.name]: keyName, [key.child]: [childData] });
319    }
320
321    return acc;
322  }, []);
323}
324
325// Generate manufacturer/device structure
326const manufacturers = generateTree(source, {
327  name: 'manufacturer', // Key name to use as grouping identifier
328  child: 'devices', // Key name for child data
329});
330
331// Generate device/model structure
332manufacturers.forEach((manufacturer) => {
333  manufacturer.devices = generateTree(manufacturer.devices, {
334    name: 'device',
335    child: 'models',
336  });
337
338  // Generate model/data structure
339  manufacturer.devices.forEach((device) => {
340    device.models = generateTree(device.models, {
341      name: 'model',
342      child: 'data',
343    });
344  });
345});
346
347const destination = [{ manufacturers }];
348
349console.log(destination);

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

QUESTION

What does Kubelet use to determine the ephemeral-storage capacity of the node?

Asked 2022-Feb-18 at 09:04

I have Kubernetes cluster running on a VM. A truncated overview of the mounts is:

1$ df -h
2Filesystem                    Size  Used Avail Use% Mounted on
3/dev/sda1                      20G  4.5G   15G  24% /
4/dev/mapper/vg001-lv--docker  140G   33G  108G  23% /var/lib/docker
5

As you can see, I added an extra disk to store the docker images and its volumes. However, when querying the node's capacity, the following is returned

1$ df -h
2Filesystem                    Size  Used Avail Use% Mounted on
3/dev/sda1                      20G  4.5G   15G  24% /
4/dev/mapper/vg001-lv--docker  140G   33G  108G  23% /var/lib/docker
5Capacity:
6  cpu:                12
7  ephemeral-storage:  20145724Ki
8  hugepages-1Gi:      0
9  hugepages-2Mi:      0
10  memory:             65831264Ki
11  nvidia.com/gpu:     1
12  pods:               110
13

ephemeral-storage is 20145724Ki which is 20G, referring to the disk mounted at /.

How does Kubelet calculate its ephemeral-storage? Is it simply looking at the disk space available at /? Or is it looking at another folder like /var/log/containers?

This is a similar post where the user eventually succumbed to increasing the disk mounted at /.

ANSWER

Answered 2022-Feb-18 at 09:04

Some theory

By default Capacity and Allocatable for ephemeral-storage in standard kubernetes environment is sourced from filesystem (mounted to /var/lib/kubelet). This is the default location for kubelet directory.

The kubelet supports the following filesystem partitions:

  1. nodefs: The node's main filesystem, used for local disk volumes, emptyDir, log storage, and more. For example, nodefs contains /var/lib/kubelet/.
  2. imagefs: An optional filesystem that container runtimes use to store container images and container writable layers.

Kubelet auto-discovers these filesystems and ignores other filesystems. Kubelet does not support other configurations.

From Kubernetes website about volumes:

The storage media (such as Disk or SSD) of an emptyDir volume is determined by the medium of the filesystem holding the kubelet root dir (typically /var/lib/kubelet).

Location for kubelet directory can be configured by providing:

  1. Command line parameter during kubelet initialization

--root-dir string Default: /var/lib/kubelet

  1. Via kubeadm with config file (e.g.)
1$ df -h
2Filesystem                    Size  Used Avail Use% Mounted on
3/dev/sda1                      20G  4.5G   15G  24% /
4/dev/mapper/vg001-lv--docker  140G   33G  108G  23% /var/lib/docker
5Capacity:
6  cpu:                12
7  ephemeral-storage:  20145724Ki
8  hugepages-1Gi:      0
9  hugepages-2Mi:      0
10  memory:             65831264Ki
11  nvidia.com/gpu:     1
12  pods:               110
13apiVersion: kubeadm.k8s.io/v1beta3
14kind: InitConfiguration
15nodeRegistration:
16  kubeletExtraArgs:
17    root-dir: "/data/var/lib/kubelet"
18

Customizing kubelet:

To customize the kubelet you can add a KubeletConfiguration next to the ClusterConfiguration or InitConfiguration separated by --- within the same configuration file. This file can then be passed to kubeadm init.

When bootstrapping kubernetes cluster using kubeadm, Capacity reported by kubectl get node is equal to the disk capacity mounted into /var/lib/kubelet

However Allocatable will be reported as: Allocatable = Capacity - 10% nodefs using the standard kubeadm configuration, since the kubelet has the following default hard eviction thresholds:

  • nodefs.available<10%

It can be configured during kubelet initialization with: -eviction-hard mapStringString Default: imagefs.available<15%,memory.available<100Mi,nodefs.available<10%


Example

I set up a test environment for Kubernetes with a master node and two worker nodes (worker-1 and worker-2).

Both worker nodes have volumes of the same capacity: 50Gb.

Additionally, I mounted a second volume with a capacity of 20Gb for the Worker-1 node at the path /var/lib/kubelet. Then I created a cluster with kubeadm.

Result

From worker-1 node:

1$ df -h
2Filesystem                    Size  Used Avail Use% Mounted on
3/dev/sda1                      20G  4.5G   15G  24% /
4/dev/mapper/vg001-lv--docker  140G   33G  108G  23% /var/lib/docker
5Capacity:
6  cpu:                12
7  ephemeral-storage:  20145724Ki
8  hugepages-1Gi:      0
9  hugepages-2Mi:      0
10  memory:             65831264Ki
11  nvidia.com/gpu:     1
12  pods:               110
13apiVersion: kubeadm.k8s.io/v1beta3
14kind: InitConfiguration
15nodeRegistration:
16  kubeletExtraArgs:
17    root-dir: &quot;/data/var/lib/kubelet&quot;
18skorkin@worker-1:~# df -h
19Filesystem      Size  Used Avail Use% Mounted on
20/dev/sda1        49G  2.8G   46G   6% /
21...
22/dev/sdb         20G   45M   20G   1% /var/lib/kubelet
23

and

1$ df -h
2Filesystem                    Size  Used Avail Use% Mounted on
3/dev/sda1                      20G  4.5G   15G  24% /
4/dev/mapper/vg001-lv--docker  140G   33G  108G  23% /var/lib/docker
5Capacity:
6  cpu:                12
7  ephemeral-storage:  20145724Ki
8  hugepages-1Gi:      0
9  hugepages-2Mi:      0
10  memory:             65831264Ki
11  nvidia.com/gpu:     1
12  pods:               110
13apiVersion: kubeadm.k8s.io/v1beta3
14kind: InitConfiguration
15nodeRegistration:
16  kubeletExtraArgs:
17    root-dir: &quot;/data/var/lib/kubelet&quot;
18skorkin@worker-1:~# df -h
19Filesystem      Size  Used Avail Use% Mounted on
20/dev/sda1        49G  2.8G   46G   6% /
21...
22/dev/sdb         20G   45M   20G   1% /var/lib/kubelet
23Capacity:
24  cpu:                2
25  ephemeral-storage:  20511312Ki
26  hugepages-1Gi:      0
27  hugepages-2Mi:      0
28  memory:             4027428Ki
29  pods:               110
30

Size of ephemeral-storage is the same as volume mounted at /var/lib/kubelet.

From worker-2 node:

1$ df -h
2Filesystem                    Size  Used Avail Use% Mounted on
3/dev/sda1                      20G  4.5G   15G  24% /
4/dev/mapper/vg001-lv--docker  140G   33G  108G  23% /var/lib/docker
5Capacity:
6  cpu:                12
7  ephemeral-storage:  20145724Ki
8  hugepages-1Gi:      0
9  hugepages-2Mi:      0
10  memory:             65831264Ki
11  nvidia.com/gpu:     1
12  pods:               110
13apiVersion: kubeadm.k8s.io/v1beta3
14kind: InitConfiguration
15nodeRegistration:
16  kubeletExtraArgs:
17    root-dir: &quot;/data/var/lib/kubelet&quot;
18skorkin@worker-1:~# df -h
19Filesystem      Size  Used Avail Use% Mounted on
20/dev/sda1        49G  2.8G   46G   6% /
21...
22/dev/sdb         20G   45M   20G   1% /var/lib/kubelet
23Capacity:
24  cpu:                2
25  ephemeral-storage:  20511312Ki
26  hugepages-1Gi:      0
27  hugepages-2Mi:      0
28  memory:             4027428Ki
29  pods:               110
30skorkin@worker-2:~# df -h
31Filesystem      Size  Used Avail Use% Mounted on
32/dev/sda1        49G  2.7G   46G   6% /
33

and

1$ df -h
2Filesystem                    Size  Used Avail Use% Mounted on
3/dev/sda1                      20G  4.5G   15G  24% /
4/dev/mapper/vg001-lv--docker  140G   33G  108G  23% /var/lib/docker
5Capacity:
6  cpu:                12
7  ephemeral-storage:  20145724Ki
8  hugepages-1Gi:      0
9  hugepages-2Mi:      0
10  memory:             65831264Ki
11  nvidia.com/gpu:     1
12  pods:               110
13apiVersion: kubeadm.k8s.io/v1beta3
14kind: InitConfiguration
15nodeRegistration:
16  kubeletExtraArgs:
17    root-dir: &quot;/data/var/lib/kubelet&quot;
18skorkin@worker-1:~# df -h
19Filesystem      Size  Used Avail Use% Mounted on
20/dev/sda1        49G  2.8G   46G   6% /
21...
22/dev/sdb         20G   45M   20G   1% /var/lib/kubelet
23Capacity:
24  cpu:                2
25  ephemeral-storage:  20511312Ki
26  hugepages-1Gi:      0
27  hugepages-2Mi:      0
28  memory:             4027428Ki
29  pods:               110
30skorkin@worker-2:~# df -h
31Filesystem      Size  Used Avail Use% Mounted on
32/dev/sda1        49G  2.7G   46G   6% /
33Capacity:
34  cpu:                2
35  ephemeral-storage:  50633164Ki
36  hugepages-1Gi:      0
37  hugepages-2Mi:      0
38  memory:             4027420Ki
39  pods:               110  
40

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

QUESTION

Create list of strings from nested list of indices and nested list of strings

Asked 2022-Feb-04 at 03:35

I have two nested lists: one that holds lists of indices, and the other with lists of strings. The 0th indices sublist corresponds to the 0th strings sublist. Inside of each indices sublist are the indices of the strings of the corresponding strings sublist that I want to pull into a new nested list.

1nested_indices = [[3,4,5],[0,1,2],[6,7,8]]
2strings_list = [['0a','0b','0c','0d','0e','0f','0g','0g','0h', '0i'],
3           ['1a','1b','1c','1d','1e','1f','1g','1g','1h', '1i'],
4           ['2a','2b','2c','2d','2e','2f','2g','2g','2h', '2i'],
5           ['3a','3b','3c','3d','3e','3f','3g','3g','3h', '3i'],
6           ['4a','4b','4c','4d','4e','4f','4g','4g','4h', '4i'],
7           ['5a','5b','5c','5d','5e','5f','5g','5g','5h', '5i'],
8           ['6a','6b','6c','6d','6e','6f','6g','6g','6h', '6i'],
9           ['7a','7b','7c','7d','7e','7f','7g','7g','7h', '7i'],
10           ['8a','8b','8c','8d','8e','8f','8g','8g','8h', '8i'],
11           ['9a','9b','9c','9d','9e','9f','9g','9g','9h', '9i']]
12

The lists inside nested_indices will be variable length in use. But for this example, this is what I'm hoping to get:

1nested_indices = [[3,4,5],[0,1,2],[6,7,8]]
2strings_list = [['0a','0b','0c','0d','0e','0f','0g','0g','0h', '0i'],
3           ['1a','1b','1c','1d','1e','1f','1g','1g','1h', '1i'],
4           ['2a','2b','2c','2d','2e','2f','2g','2g','2h', '2i'],
5           ['3a','3b','3c','3d','3e','3f','3g','3g','3h', '3i'],
6           ['4a','4b','4c','4d','4e','4f','4g','4g','4h', '4i'],
7           ['5a','5b','5c','5d','5e','5f','5g','5g','5h', '5i'],
8           ['6a','6b','6c','6d','6e','6f','6g','6g','6h', '6i'],
9           ['7a','7b','7c','7d','7e','7f','7g','7g','7h', '7i'],
10           ['8a','8b','8c','8d','8e','8f','8g','8g','8h', '8i'],
11           ['9a','9b','9c','9d','9e','9f','9g','9g','9h', '9i']]
12expected=[['0d','0e','0f'],['1a','1b','1c'],['2g','2g','2h']]
13

This is my code so far, which is not only not giving me the correct values, but is also losing the nested list structure.

1nested_indices = [[3,4,5],[0,1,2],[6,7,8]]
2strings_list = [['0a','0b','0c','0d','0e','0f','0g','0g','0h', '0i'],
3           ['1a','1b','1c','1d','1e','1f','1g','1g','1h', '1i'],
4           ['2a','2b','2c','2d','2e','2f','2g','2g','2h', '2i'],
5           ['3a','3b','3c','3d','3e','3f','3g','3g','3h', '3i'],
6           ['4a','4b','4c','4d','4e','4f','4g','4g','4h', '4i'],
7           ['5a','5b','5c','5d','5e','5f','5g','5g','5h', '5i'],
8           ['6a','6b','6c','6d','6e','6f','6g','6g','6h', '6i'],
9           ['7a','7b','7c','7d','7e','7f','7g','7g','7h', '7i'],
10           ['8a','8b','8c','8d','8e','8f','8g','8g','8h', '8i'],
11           ['9a','9b','9c','9d','9e','9f','9g','9g','9h', '9i']]
12expected=[['0d','0e','0f'],['1a','1b','1c'],['2g','2g','2h']]
13new_list = []
14
15for sublist in nested_indices:
16    for (item, index) in enumerate(sublist):
17        new_list.append(strings_list[item][index])
18        
19print(new_list)
20

Which results in: ['0d', '1e', '2f', '0a', '1b', '2c', '0g', '1g', '2h']

Where am I going wrong?

ANSWER

Answered 2022-Feb-04 at 03:28

Use:

  • zip to pair corresponding sublists in both nested lists
  • list comprehension to get the corresponding values from paired sublists

Code

1nested_indices = [[3,4,5],[0,1,2],[6,7,8]]
2strings_list = [['0a','0b','0c','0d','0e','0f','0g','0g','0h', '0i'],
3           ['1a','1b','1c','1d','1e','1f','1g','1g','1h', '1i'],
4           ['2a','2b','2c','2d','2e','2f','2g','2g','2h', '2i'],
5           ['3a','3b','3c','3d','3e','3f','3g','3g','3h', '3i'],
6           ['4a','4b','4c','4d','4e','4f','4g','4g','4h', '4i'],
7           ['5a','5b','5c','5d','5e','5f','5g','5g','5h', '5i'],
8           ['6a','6b','6c','6d','6e','6f','6g','6g','6h', '6i'],
9           ['7a','7b','7c','7d','7e','7f','7g','7g','7h', '7i'],
10           ['8a','8b','8c','8d','8e','8f','8g','8g','8h', '8i'],
11           ['9a','9b','9c','9d','9e','9f','9g','9g','9h', '9i']]
12expected=[['0d','0e','0f'],['1a','1b','1c'],['2g','2g','2h']]
13new_list = []
14
15for sublist in nested_indices:
16    for (item, index) in enumerate(sublist):
17        new_list.append(strings_list[item][index])
18        
19print(new_list)
20new_list = [[vals[i] for i in idxs] for idxs, vals in zip(nested_indices, strings_list)]
21

Result

1nested_indices = [[3,4,5],[0,1,2],[6,7,8]]
2strings_list = [['0a','0b','0c','0d','0e','0f','0g','0g','0h', '0i'],
3           ['1a','1b','1c','1d','1e','1f','1g','1g','1h', '1i'],
4           ['2a','2b','2c','2d','2e','2f','2g','2g','2h', '2i'],
5           ['3a','3b','3c','3d','3e','3f','3g','3g','3h', '3i'],
6           ['4a','4b','4c','4d','4e','4f','4g','4g','4h', '4i'],
7           ['5a','5b','5c','5d','5e','5f','5g','5g','5h', '5i'],
8           ['6a','6b','6c','6d','6e','6f','6g','6g','6h', '6i'],
9           ['7a','7b','7c','7d','7e','7f','7g','7g','7h', '7i'],
10           ['8a','8b','8c','8d','8e','8f','8g','8g','8h', '8i'],
11           ['9a','9b','9c','9d','9e','9f','9g','9g','9h', '9i']]
12expected=[['0d','0e','0f'],['1a','1b','1c'],['2g','2g','2h']]
13new_list = []
14
15for sublist in nested_indices:
16    for (item, index) in enumerate(sublist):
17        new_list.append(strings_list[item][index])
18        
19print(new_list)
20new_list = [[vals[i] for i in idxs] for idxs, vals in zip(nested_indices, strings_list)]
21[['0d', '0e', '0f'], ['1a', '1b', '1c'], ['2g', '2g', '2h']]
22

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

QUESTION

My emulator date input type has a forward slash (/), my device does not?

Asked 2022-Jan-03 at 20:34

Problem: My emulator date input type has a forward slash and numbers (/), my device does not?

I'm not sure what to try on this, except I had to create a workaround which involved using a text field with an `android:digits="0123456789/" constraint. Any thoughts on the reason why?

The physical device is a Samsung A32 5G it has numbers only and no '/' and the emulator does.

... was this ...

1android:inputType=&quot;date&quot;
2

... now this ...

1android:inputType=&quot;date&quot;
2android:inputType=&quot;text&quot;
3android:digits=&quot;@string/allowDateCharacters&quot;
4

ANSWER

Answered 2022-Jan-03 at 20:34

Problem: My emulator date input type has a forward slash and numbers (/), my device does not?

This is not a problem.

There are ~3 billion Android devices in use, across tens of thousands of device models. There are dozens of soft keyboards ("input method editors") that ship pre-installed on those device models, and there are dozens more that those billions of users can install from the Play Store and elsewhere.

What keys a soft keyboard offers for a given android:inputType is up to the developers of the soft keyboard — it is not up to you or I. Consider android:inputType to be a suggestion, not a command.

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

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in 5G

Tutorials and Learning Resources are not available at this moment for 5G

Share this Page

share link

Get latest updates on 5G