How to read a file in and replace the value with a name - perl

I have a file of with what I will call source IDs. I want to read that file and based on the source ID add a name to it, for example 15431 = MyTV8. I have a file that lists the source ID and the name, but I'm not sure how to read the original IDs in and add the names from the channel map file to the file with the source IDs.
A small sample of the source IDs I poll
13431
0
4112
4129
11412
0
0
12055
0
0
4129
0
0
12125
12120
0
10959
5370
5380
4109
0
20121
0
12334
11493
0
0
4107
5687
0
4008
0
0
4166
5378
4203
0
12056
0
0
0
0
4286
4183
0
0
4129
4037
0
10555
12209
11205
8846
0
0
5380
4719
0
4166
4117
4150
0
4183
0
4123
10391
0
4183
4151
5531
4107
4179
4185
4203
4203
0
4107
They are just in a text file and here is the source-ID channel map
1052 SCIFI
1053 COMEDY
1066 CSPAN2
1067 ESPN CLASSIC
1100 SUNSHINE FOOTBALL
1133 TRUTV
1241 SHOWTIME 2 EAST
1312 MC METAL
1315 MC KIDS ONLY
1318 MC HIP HOP & R&B
1319 MC MC MIX TAPE
1324 MC LITE CLASSICAL
1326 MC SINGERS & SWING
1330 MC R&B CLASSICS
1332 MC MEXICANA
1334 MC RAGGAE
1338 MC HIP HOP CLASSICS
1339 MC SOUND OF SEASON
1340 MC HIT LIST
1346 MC PARTY FAVORITES
1348 MC POP HITS
2006 COLLEGE SPORTS TV
2469 WGCU WORLD
2470 WGCU ED TV
3014 ACTION MAX WEST
3048 SHOWTIME SHOWCASE 3
3051 STARZ! 1 WEST
3059 JEWELRY TV
3064 STARZ! IN BLACK
3068 WAM.
3069 STARZ! 5 CINEMA WEST
3093 NICK TOO
4003 ACTION WEST
4008 NOGGIN
4011 ENCORE DRAMA EAST
4029 LOGO MTV
4037 MOVIEPLEX
4068 FCS SOCC
4070 EWTN DIGITAL
4081 TELEFUTURA
4100 ADS-AMC
4101 ADS-A&E
4103 ADS-BET
4104 ADS-BRVO
4105 ADS-C-SPAN
4107 ADS-TOON
4108 ADS-CMT
4109 ADS-CNBC
4110 ADS-CNN
4112 ADS-CMDY
4115 ADS-TRUTV/COURT-TV
4117 ADS-E!
4119 ADS-ESPN
4120 ADS-ESPN2
4121 ADS-EWTN
4123 ADS-HALLMARK
4124 FIT TV
4125 ADS-FX
4127 ADS-CCTV
4128 ADS-HIST
4129 ADS-HGTV
4130 ADS-HSN
4150 ADS-MSNBC
4151 ADS-MTV
4156 ADS-NICK
4157 BARKER
4159 PLAYBOY DIR. CUT /CP
4163 ADS-STYLE
4164 ADS-QVC
4166 ADS-SCIFI
4178 ADS-DSC
4179 ADS-FAM
4181 ADS-TLC
4182 ADS-SPIKE
4183 ADS-USA
4184 ADS-TWC-DIGITAL
4185 ADS-TNT
4186 ADS-FOOD
4187 ADS-VH-1
4203 ADS-FXNEW
4241 ADS-TRAVL
4286 ADS-TCM
4460 GAME SHOW
4485 MTV2.
4545 SUNDANCE EAST
4557 ADS-TVL
4702 ADS-VERSUS
4705 ADS-SPEED
4719 ADS-GOLF
4730 ADS-WGN
5012 ADS TEST 1
5013 ADS TEST 2
5014 ADS TEST 3
5015 ADS TEST 4
5016 ADS TEST 5
5017 ADS TEST 6
5018 ADS TEST 7
5019 ADS TEST 8
5020 ADS TEST 9
5021 ADS TEST 10
5022 ADS TEST 11
5023 ADS TEST 12
5024 SUN SPORTS HD
5286 SHOP NBC.
5368 ADS-WEDU
5369 ADS-WXPX
5370 ADS-WFLA
5377 ADS-WTOG
5378 ADS-WTSP
6031 ADS-WRXY
6166 ADS-WWSB
6206 ADS-WZVN
6884 DXD / TOON DISNEY
7064 MY38 WB HD
7077 BLOOMBERG TV
7085 BIG TEN
7086 BIG TEN 2
7090 ADS-HALLMARK VS
7331 CURRENT TV
7795 G4.
8282 BIOGRAPHY
8285 HISTORY INTER.
8434 ADS-WTTA
8445 OUTDOOR CH
8499 OXYGEN
8675 DO IT YOURSELF
8841 WEATHERSCAN
8846 LIFETIME MOVIE NET.
8888 BRAVO
9144 NHL & MLB GAME 1
9145 NHL & MLB GAME 2
9145 NHL & MLB GAME 2
9145 NHL & MLB GAME 2
9146 NHL & MLB GAME 3
9146 NHL & MLB GAME 3
9147 NHL & MLB GAME 4
9147 NHL & MLB GAME 4
9147 NHL & MLB GAME 4
9148 NHL & MLB GAME 5
9148 NHL & MLB GAME 5
9148 NHL & MLB GAME 5
9149 NHL & MLB GAME 6
9149 NHL & MLB GAME 6
9149 NHL & MLB GAME 6
9150 NHL & MLB GAME 7
9150 NHL & MLB GAME 7
9150 NHL & MLB GAME 7
9151 NHL & MLB GAME 8
9151 NHL & MLB GAME 8
9151 NHL & MLB GAME 8
9152 NHL & MLB GAME 9
9152 NHL & MLB GAME 9
9152 NHL & MLB GAME 9
9153 NHL & MLB GAME 10
9153 NHL & MLB GAME 10
9201 FUSE
9237 THEN / GAS
9472 C-SPAN3
9544 TV GAMES
9550 SOAPNET
9597 GAC
10000 CINEMAX
10001 ENCORE EAST
10002 HBO-2
10004 HBO-3 SIGNATURE
10005 SHOWTIME EAST
10006 STARZ! 1 EAST
10008 DISNEY CHANNEL.
10010 TMC
10011 SHOWTIME EXTREME E
10012 HBO WEST
10014 CINEMAX WEST
10021 ADS-ANPL
10023 CINEMAX MORE MAX -2
10025 TMC XTRA 2 EAST
10026 ACTION MAX EAST
10028 THRILLER MAX EAST
10041 NICKTOONS
10042 MTV JAMS
10045 VH-1 SOUL
10046 CMT PURE
10057 OUTERMAX EAST
10063 STARZ! 4 KIDS FAMILY
10065 STARZ! 5 CINEMA EAST
10067 VH-1 CLASSIC
10098 HBO LATINO E
10389 WORD
10391 NATIONAL GEOGRAPHIC
10398 DAYSTAR TV
10475 SHOWTIME FAMILY
10555 #MAX EAST
10556 WOMANMAX
10558 5STARMAX EAST
10584 FCS ATL
10585 FCS CEN
10586 FCS PAC
10911 SHOWTIME HDTV
10935 THEATER HD CMCHD4
10959 MTV HITS
10962 FINE LIVING/COOK TV
11101 ADS-CW6/WTVK46
11126 ADS-PAX / ION
11132 ADS-WMOR
11205 ADS-SNN
11242 RFD-TV
11299 ADS-ESPN HD
11320 ADS-LIFE
11324 ADS-FSN-FLORIDA
11328 ADS-CC-SPORT-S
11406 ADS-DHC
11411 ADS-SUN
11412 ADS-CNN-HDLN
11414 ESPNU
11431 NBA TV
11446 SPORTSMAN
11493 TENNIS TV
11514 ESPN SPPV1
11515 ESPN SPPV2
11516 ESPN SPPV3
11517 ESPN SPPV4
11518 ESPN SPPV5
11519 ESPN SPPV6
11647 GOL TV
11684 UNIVERSAL HD CMCHD2
11714 STARZ COMEDY
11716 STARZ HD
11855 TV ONE.
11911 ADS-TNTHD
12002 CENTRIC
12016 HBO EAST
12020 IFC
12023 LOVE STORIES E.
12027 MYSTERY EAST
12030 OVATION
12032 SHOWTIME 2 EAST
12037 STARZ! EDGE
12044 WESTERNS EAST
12045 ACTION EAST
12049 DISCOVERY KIDS
12050 PLANET GREEN
12051 DISCOVERY SCIENCE
12055 WE.
12056 MILITARY CHANNEL.
12112 ESPNEWS
12120 DISC ID
12125 NFL NETWORK
12130 FLIX EAST
12174 SHOWTIME BEYOND EAST
12175 BBC AMERICA
12209 ADS-TBS
12306 ADS-REALTY-TV-PC
12333 ADS-LOPC
12334 ADS-ACCESS-CH-19
12336 ADS-SARASOTA-ED
12339 ADS-LO
12340 ADS-TV-GUIDE
12393 WXPXHD
12800 ADS-ESPN2HD
12810 WFTX FOX HD
12817 ADS-TBS HD
13008 HBO ZONE EAST
13011 HBO FAMILY EAST
13013 HBO COMEDY EAST
13017 WZVN PC HDTV
13039 WBBH PC HDTV
13050 NAT GEO WILD
13072 HALLMARK MOVIE CH
13104 GOSPEL MUSIC TV
13135 HBO HD CMCHD5
13136 MAX HD CMCHD5
13229 SPROUT "E" NETWORKS
13268 WFLA NBC HD
13289 WTVT FOX HD
13406 EMPLOYEE CHANNEL
13430 INDIEPLEX
13431 RETROPLEX
13467 ADS-SCI-FI HD
13551 PALADIEA HD
13738 HGTV HD CMCHD1
13745 NATGEO HD CMCHD3
13907 TV FOOD HD CMCHD2
14102 NFLHD
14507 ADS-WNFM-8
14710 A&E HD CMCHD1
15000 IN DEMAND 1
15001 IN DEMAND 2
15045 SHORTEEZ ADULT
15067 NBA TEAM 1
15068 NBA TEAM 2
15069 NBA TEAM 3
15070 NBA TEAM 4
15071 NBA TEAM 5
15072 NBA TEAM 6
15073 NBA TEAM 7
15074 NBA TEAM 8
15075 NBA TEAM 9
15076 NBA TEAM 10
15128 REELZ
15201 VERSUS - HD
15238 NHL & MLB GAME 14
15239 NHL & MLB GAME 13
15240 NHL & MLB GAME 12
15241 NHL & MLB GAME 11
15364 MTV SPANISH TR3
15542 PENTHOUSE/TEN ADULT
16116 ADS-FOX BUSINESS
16120 ANIMAL HD CMCHD4
16121 SCIENCE HD CMCHD8
16122 TDC HD CMCHD3
16123 TLC HD CMCHD5
16129 USA HD CMCHD3
16141 CNN HD CMCHD7
16240 LIFETIME MOVIENET HD
16280 NHL NETWORK
16317 RETIREMENT TV
16346 FX HD CMCHD9
16403 GOLF HD CMCHD7
16414 AMC HD CMCHD7
16430 BIOGRAPHY HD
16543 SPEED HD CMCHD9
16547 SPIKE HD
16686 DISNEY HD CMCHD-8
16692 FAMILY HD CMCHD8
16713 NICKELODEON HD
16756 FOX NEWS HD CMCHD9
16788 WEDU HD
16792 WTSP DIGITAL WEATHER
16793 WTSP HDTV
16798 LIFETIME HD
16807 WWSB HDTV
16817 PLANET GREEN HD
17000 FRESH ADULT
17512 MLB NETWORK
17535 MLBHD
18030 WGCU HD PBS
18324 HEADLINE NEWS HD
18333 TCM HD
18411 TRU TV HD
18630 FOX SPORTSNET FL HD
19005 3DTV 1
19421 3DTV 2
20101 MC 90'S
20102 MC ADULT ALTERNATIVE
20104 MC RAP
20105 MC THROWBACK JAMZ
20106 MC CONTEMP CHRISTIAN
20107 MC CLASSIC COUNTRY
20108 MC TODAY'S COUNTRY
20110 MC ROCK
20112 MC GOSPEL
20113 MC RETRO ROCK
20115 MC TODDLER TUNES
20116 MC SOFT ROCK
20119 MC SOUNDSCAPES
20120 MC JAZZ
20121 MC SMOOTH JAZZ
20122 MC CLASSICAL MASTERP
20124 MC 80'S
20126 MC EASY LISTENING
20127 MC POP LATINO
20128 MC SOLID GOLD OLDIES
20129 MC R&B SOUL
20131 MC TRUE COUNTRY
20282 MC STAGE & SCREEN
20284 MC MUSICA URBANA
20287 MC TROPICALS
20289 MC CLASSIC ROCK
20338 MC CLASSIC ALTERNATV
20339 MC DANCE ELECTRONICA
20357 MC ALTERNATIVE
20358 MC ROMANCES
20359 MC BLUES
20360 MC 70'S
21170 STARZ! HD CMCHD1
21203 SCI FI HD CMCHD2
21442 THC HD CMCHD4
23104 E! HD
23105 TRAVEL HD
23106 CARTOON HD
23107 CSS HD.
23109 NFL RED ZONE
23110 IND HDPPV
23111 IND HDPPV2
23112 ESPNU HD

There is a general pattern here, and it is this: this is a set intersection problem, and as such can be solved easily with Perl "sets", which we tend to call hashes :).
The approach is to create a set out of one of your data files (ie. indexing it into a hash table, like so: %set = (a => 1, b => 1, c => 1), where the actual value is immaterial, since we're going to be testing it with the "set membership operator" exists).
Once you have that, it is a simple matter of going through the other data set, and test membership of one of its keys (in your case, source IDs) in the %set above.
So, assuming the channel map file is in the following format:
ID,NAME
and the source ID file is just one ID per line, the you could do the following:
open my $CHANNEL_MAP, q{<}, $channel_map_file_name or die $!;
my %channel_map
= map {
chomp;
my #mapping = split /,/;
$mapping[0] => $mapping[1] # not needed, just being explicit.
} <$CHANNEL_MAP>;
close $CHANNEL_MAP or die $!;
# source ID file passed as a command line argument
while (<>) {
chomp;
print "$_ = $channel_map{$_}\n"
if exists $channel_map{$_};
}
However, this seems a bit pointless, since all you seem to want to do is to filter the channel map file by the existing source IDs. In that case, you could simply index the source ID file instead (use the technique above), and then simply go through the channel mappings file and print each line for which the ID exists in your source IDs.

It's all rather fuzzy since you're not clear on the formats of your files.
But, assuming you have a file called names.txt that lists the name in the "15431 = MyTV8" format, one per line, and you have the other file while lists only numbers, you could use something like this:
#!/usr/bin/perl
open NAMES, '< names.txt' or die $#;
my %names = map { /(\d+) = (.+)/; ($1, $2) } (<NAMES>);
while (<>)
{
chomp;
if (exists $names{$_}) {
print "$_ = $names{$_}\n";
} else {
print "$_\n";
}
}

Related

I want to search through <dynamic> List in dart

I have a list of products, the list is below:
List<dynamic>products = [
{
"id": 3,
"name": "Apple MacBook Air 13.3-Inch 10th Gen Core i3-1.1GHz, 8GB RAM, 256GB SSD (MWTJ2) Space Gray 2020",
"price": 126000,
"descriptions": "Processor\tIntel Core i3-1000NG4 Processor (4M Cache, 1.10 GHz up to 3.20 GHz)\r\n\r\nMemory\t 8GB 3733MHz LPDDR4X onboard RAM\r\n\r\nStorage\t 256GB SSD\r\nGraphics\tIntel Iris Plus Graphics; **Support for Thunderbolt 3–enabled external graphics processors (eGPUs)\r\n\r\nDisplay\t 13.3-inch (diagonal) Retina LED-backlit display with IPS technology; 2560-by-1600 native resolution at 227 pixels per inch with support for millions of colors\r\n\r\nAdapter\t 30W USB-C Power Adapter; USB-C power port\r\n\r\nBattery\tUp to 10 hours battery back (Video & web browsing up to 05 hours depending on resolution) Built-in 49.9 watt-hours lithium-polymer battery\r\n\r\nOperating System\tmacOS\r\n\r\nNetworking\t 802.11ac Wi-Fi wireless networking; IEEE 802.11a/b/g/n compatible\r\n\r\nTouchpad\t Multi-Touch gestures\r\n\r\nKeyboard\tBacklit Keyboard - US English Retina is equipped with: 78 keys (ANSI specification) or 79 keys (ISO specification), including 12 function keys and 4 direction keys arranged in an \"inverted T\" shape. Ambient light sensor Force touchpad brings precise cursors Control and pressure-sensing functions, support forceful long-press, acceleration function, pressure-sensitive drawing, and multi-touch gestures\r\n\r\nBluetooth\tBluetooth 5.0 wireless technology\r\n\r\nAudio\t Stereo speakers; Wide stereo sound; Support for Dolby Atmos playback; Three-mic array with directional beamforming; 3.5 mm headphone jack\r\n\r\nOptical Drive None\r\n\r\nSoftware\tFinal Cut Pro X; Logic Pro X\r\n\r\nWebCam\t720p FaceTime HD camera\r\n\r\nFingerprint\tYes\r\n\r\nDisplay Touch\tDisplay WithTouch ID sensor\r\n\r\nPorts & Connectors\t2 x Thunderbolt 3 (Supports DisplayPort and Power Delivery); Thunderbolt (up to 40Gb / s); USB 3.1 Gen 2 (up to 10Gb / s; 1 x HDMI; 1 x VGA; 1 x 3.5 mm Headphone Output\r\n\r\nColor\tSpace Gray\r\n\r\nDimensions (W x D x H)\tThickness: 0.41 to 1.61 cm (0.16 to 0.63 inches); Width: 30.41 cm (11.97 inches); Depth: 21.24 cm (8.36 inches)\r\n\r\nWeight\t1.29 kg (2.8 lbs)\r\n\r\nIncluded in the Box\tMacBook Air; 30W USB-C Power Adapter; USB-C Charge Cable (2 m)\r\n\r\nWarranty \t01 year International Limited Warranty (Terms & Condition Apply As Per Apple)",
"image": "/images/macbook_IU3NvNF.jpg",
"created_at": "2022-08-19T17:42:13.118095Z",
"updated_at": "2022-08-19T17:42:13.118095Z",
"stock": true,
"category": 1,
"user": "mosta"
},
{
"id": 2,
"name": "MSI Modern 14 B10MW Core i3 10th Gen 14\" Full HD Laptop",
"price": 50890,
"descriptions": "Processor Intel Core i3 10110U Processor (4MB Cache, 2.1Ghz up to 4.1Ghz)\r\n\r\nDisplay 14.0\" FHD (1920x1080), IPS-Level Display\r\n\r\nMemory 4GB 2666MHz DDR4 RAM, (Suppoorted Up to 16GB)\r\n\r\nStorage 256GB NVMe SSD (Supported Up to 1TB)\r\n\r\nGraphics Intel UHD Graphics\r\n\r\nOperating System Free Dos\r\nBattery 39.3Whr\r\n\r\nAdapter 65W adapter\r\n\r\nInput Devices\r\nKeyboard Backlight Keyboard\r\n\r\nWebCam HD type (30fps#720p)\r\nCard Reader 1x Micro SD\r\n\r\nNetwork & Wireless Connectivity\r\nWi-Fi 802.11 ac Wi-Fi\r\n\r\nBluetooth Bluetooth v5\r\n\r\nPorts, Connectors & Slots\r\nUSB (s) 2x Type-A USB2.0\r\n\r\n1x Type-C USB3.2 Gen2\r\n\r\nHDMI 1x (4K # 30Hz) HDMI\r\n\r\nAudio Jack Combo 1x Mic-in/Headphone-out Combo Jack\r\n\r\nExtra RAM Slot NO\r\n\r\nExtra M.2 Slot NO\r\n\r\nPhysical Specification\r\nDimensions (W x D x H) 319 x 220.2 x 16.9 mm\r\n\r\nWeight 1.3 kg\r\n\r\nColor(s) Carbon Gray\r\n\r\nWarranty\r\nManufacturing Warranty 02 Year",
"image": "/images/msi_sCwzOcI.jpeg",
"created_at": "2022-08-19T17:41:53.358014Z",
"updated_at": "2022-08-19T17:41:53.358014Z",
"stock": true,
"category": 1,
"user": "mosta"
},
{
"id": 1,
"name": "iPhone 13 Pro Max",
"price": 169000,
"descriptions": "First Release\tSeptember 24, 2021\r\n\r\nColors\tGraphite, Gold, Silver, Sierra Blue\r\n\r\nNetwork\t2G, 3G, 4G, 5G\r\n\r\nSIM\tNano / Electronic SIM\r\n\r\nWLAN\t✅ dual-band, Wi-Fi hotspot\r\n\r\nBluetooth\t✅ v5.0, A2DP, LE\r\n\r\nGPS\t✅ A-GPS, GLONASS, GALILEO, BDS, QZSS\r\n\r\nRadio\t✖\r\n\r\nUSB\tLightning, USB 2.0\r\n\r\nOTG\t✅\r\n\r\nUSB Type-C\t✖ (Proprietary reversible connector)\r\n\r\nNFC\t✅\r\n\r\nStyle\tNotch\r\n\r\nMaterial\t Gorilla Glass front & back, stainless steel frame\r\n\r\nWater Resistance\t✅ IP68 dust/water resistant (up to 6m for 30 mins)\r\n\r\nDimensions\t160.8 x 78.1 x 7.7 mmillimeters\r\n\r\nWeight\t240 grams\r\n\r\nSize\t6.7 inches\r\n\r\nResolution\t1284 x 2778 pixels (458 ppi)\r\n\r\nTechnology\tSuper Retina XDR OLED Touchscreen\r\n\r\nProtection\t✅ Scratch-resistant ceramic glass, oleophobic coating\r\n\r\nFeatures\tDolby Vision, HDR10, 1200 nits (max.), 120Hz, true-tone, wide color gamut\r\n\r\nResolution\tQuad 12+12+12 Megapixel + TOF 3D LiDAR scanner\r\n\r\nFeatures\tDual Pixel PDAF, sensor-shift OIS, dual-LED flash, ultrawide, depth, telephoto, 3x optical zoom & more\r\n\r\nVideo Recording\t4K (2160p), Dolby Vision HDR, ProRes, Cinematic mode, stereo sound rec.\r\n\r\nResolution\tDual 12 Megapixel + SL 3D\r\n\r\nFeatures\tF/2.2, HDR, 1/3.6″, depth / biometrics sensor\r\n\r\nVideo Recording\t4K (2160p), gyro-EIS\r\n\r\nType and Capacity\tLithium-ion 4352 mAh (non-removable)\r\n\r\nFast Charging\t✅ 27W Fast Charging (50% in 30 minutes)\r\n\r\nUSB Power Delivery 2.0\r\n\r\nWireless Charging\t✅ Fast Wireless Charging (15W MagSafe, 7.5W Qi magnetic)\r\n\r\nOperating System\tiOS 15\r\n\r\nChipset\tApple A15 Bionic (5 nm)\r\n\r\nRAM\t6 GB\r\n\r\nProcessor\tHexa-core, up to 3.22 GHz\r\n\r\nGPU\tApple GPU (5-core graphics)",
"image": "/images/iPhone13promax_YiZ3ktK.jpg",
"created_at": "2022-08-19T17:41:27.837767Z",
"updated_at": "2022-08-19T17:41:27.837767Z",
"stock": true,
"category": 2,
"user": "mosta"
}
]
I want to search through the above list by product name. And also want a make separate list contain one single map.
If i search "apple" the result should be:
List<dynamic> searchResult = [
{
"id": 3,
"name": "Apple MacBook Air 13.3-Inch 10th Gen Core i3-1.1GHz, 8GB RAM, 256GB SSD (MWTJ2) Space Gray 2020",
"price": 126000,
"descriptions": "Processor\tIntel Core i3-1000NG4 Processor (4M Cache, 1.10 GHz up to 3.20 GHz)\r\n\r\nMemory\t 8GB 3733MHz LPDDR4X onboard RAM\r\n\r\nStorage\t 256GB SSD\r\nGraphics\tIntel Iris Plus Graphics; **Support for Thunderbolt 3–enabled external graphics processors (eGPUs)\r\n\r\nDisplay\t 13.3-inch (diagonal) Retina LED-backlit display with IPS technology; 2560-by-1600 native resolution at 227 pixels per inch with support for millions of colors\r\n\r\nAdapter\t 30W USB-C Power Adapter; USB-C power port\r\n\r\nBattery\tUp to 10 hours battery back (Video & web browsing up to 05 hours depending on resolution) Built-in 49.9 watt-hours lithium-polymer battery\r\n\r\nOperating System\tmacOS\r\n\r\nNetworking\t 802.11ac Wi-Fi wireless networking; IEEE 802.11a/b/g/n compatible\r\n\r\nTouchpad\t Multi-Touch gestures\r\n\r\nKeyboard\tBacklit Keyboard - US English Retina is equipped with: 78 keys (ANSI specification) or 79 keys (ISO specification), including 12 function keys and 4 direction keys arranged in an \"inverted T\" shape. Ambient light sensor Force touchpad brings precise cursors Control and pressure-sensing functions, support forceful long-press, acceleration function, pressure-sensitive drawing, and multi-touch gestures\r\n\r\nBluetooth\tBluetooth 5.0 wireless technology\r\n\r\nAudio\t Stereo speakers; Wide stereo sound; Support for Dolby Atmos playback; Three-mic array with directional beamforming; 3.5 mm headphone jack\r\n\r\nOptical Drive None\r\n\r\nSoftware\tFinal Cut Pro X; Logic Pro X\r\n\r\nWebCam\t720p FaceTime HD camera\r\n\r\nFingerprint\tYes\r\n\r\nDisplay Touch\tDisplay WithTouch ID sensor\r\n\r\nPorts & Connectors\t2 x Thunderbolt 3 (Supports DisplayPort and Power Delivery); Thunderbolt (up to 40Gb / s); USB 3.1 Gen 2 (up to 10Gb / s; 1 x HDMI; 1 x VGA; 1 x 3.5 mm Headphone Output\r\n\r\nColor\tSpace Gray\r\n\r\nDimensions (W x D x H)\tThickness: 0.41 to 1.61 cm (0.16 to 0.63 inches); Width: 30.41 cm (11.97 inches); Depth: 21.24 cm (8.36 inches)\r\n\r\nWeight\t1.29 kg (2.8 lbs)\r\n\r\nIncluded in the Box\tMacBook Air; 30W USB-C Power Adapter; USB-C Charge Cable (2 m)\r\n\r\nWarranty \t01 year International Limited Warranty (Terms & Condition Apply As Per Apple)",
"image": "/images/macbook_IU3NvNF.jpg",
"created_at": "2022-08-19T17:42:13.118095Z",
"updated_at": "2022-08-19T17:42:13.118095Z",
"stock": true,
"category": 1,
"user": "mosta"
}]
How to approach to make this step?
import 'package:collection/collection.dart';
and use firstWhereOrNull;
example:
searchArray(String searchValue){
var test =
products.firstWhereOrNull((element) => element['name'].contains(searchValue));
print(test); //print just first object whos name property contains "MSI"
}
Or
searchArray(String searchValue) {
var test =
products.where((element) => element['name'].toString().contains(searchValue));
if (test != null) {
for (var testItem in test) {
print(testItem); //print all maps whos contains sV
}
}
}
Here is one of approach you can use to search some query through the list and add the result in another list using for in iterables
void search(String query) {
List<dynamic> searchResult = [];
for (final product in products) {
if (product["name"].toLowerCase().contains(query.toLowerCase())) {
searchResult.add(product);
print(searchResult);
return;
}
}
}
full code here
Or you can use firstWhereOrNull in dart collection as mentioned by Kendruu

How do I calculate a rolling 30 day window in KDB?

I have a keyed table of the form:
t | ar av mr mv
-----------------------------| ----------------------------------------
2016.01.04D09:51:00.000000000| -0.001061315 513 -0.01507338 576
2016.01.04D11:37:00.000000000| -0.0004846135 618 -0.001100514 583
2016.01.04D12:04:00.000000000| -0.0009708739 1619 -0.001653045 1000
I want to calculate the 30 day rolling correlation ar cor mr.
I'm stuck trying to create a self join with wj, but I'm not getting anywhere. Is this the way to do it?
You could do something like:
/-Function which creates the rolling windows (w:window size, s:list)
q)f:{[w;s] (w-1)_({ 1_x,y }\[w#0;s])}
/-e.g.
q)f[3;til 5]
0 1 2
1 2 3
2 3 4
/-Apply cor to each 30-day rolling window as below:
q)ar:exec ar from t;
q)mr:exec mr from t;
q)cor'[f[30;ar]; f[30; mr]]

Finding the values of positive peaks in smooth wave form

This is some code I wrote to search for the peaks of a very clean (no noise) signal where fun is an array containing evenly sampled data of a sine wave.
J=[fun(1)];
K=[1];
count=1;
for i=2:1.0:(length(fun)-2)
if fun(i-1)<fun(i) && fun(i)>fun(i+1)
J=[J,fun(i+1)];
K=[K,count+1];
end
count=count+1;
end
Included below is the data that I am trying to process.
The code found the peaks at the 664th and 991st entry, but none of the ones in between. I wrote the same algorithm in c++ and got the same result, so it is an algorithm problem, not language specific.
Please help me find the error or give me another solution.
fun = -1*pi/180*[-90.15
-90.00
-89.70
-89.10
-88.50
-87.75
-86.70
-85.65
-84.30
-82.95
-81.45
-79.80
-78.15
-76.35
-74.55
-72.30
-70.20
-67.80
-65.40
-62.70
-60.00
-57.15
-54.30
-51.15
-48.00
-44.85
-41.40
-37.95
-34.50
-30.90
-27.30
-23.55
-19.80
-16.05
-12.15
-8.25
-4.95
-1.50
1.95
4.80
7.80
10.65
13.95
17.40
20.70
23.85
27.15
30.30
33.45
36.45
39.45
42.45
45.30
48.00
50.70
53.40
55.95
58.35
60.75
63.15
65.25
67.35
69.45
71.40
73.20
74.85
76.50
78.15
79.50
80.85
82.05
83.25
84.15
85.05
85.95
86.70
87.45
88.05
88.50
88.95
89.10
89.25
89.40
89.25
89.10
88.95
88.50
88.05
87.45
86.70
86.10
85.20
84.30
83.25
82.20
81.00
79.65
78.15
76.65
75.00
73.35
71.55
69.60
67.50
65.40
63.30
60.90
58.65
56.10
53.55
51.00
48.30
45.45
42.60
39.75
36.75
33.75
30.60
27.45
24.30
21.00
17.70
14.40
11.10
7.65
4.80
1.95
-0.90
-4.35
-7.65
-11.10
-14.85
-18.75
-22.35
-26.10
-29.70
-33.30
-36.75
-40.20
-43.50
-46.80
-49.95
-52.95
-55.95
-58.65
-61.35
-63.90
-66.45
-68.85
-70.95
-73.05
-75.00
-76.80
-78.45
-80.10
-81.60
-82.95
-84.15
-85.20
-86.10
-87.00
-87.60
-88.05
-88.50
-88.80
-88.80
-88.80
-88.80
-88.50
-88.05
-87.60
-87.00
-86.25
-85.50
-84.45
-83.25
-82.05
-80.55
-79.05
-77.40
-75.60
-73.65
-71.55
-69.45
-67.20
-64.65
-62.25
-59.55
-56.70
-53.85
-50.85
-47.70
-44.55
-41.25
-37.95
-34.50
-30.90
-27.30
-23.70
-19.95
-16.20
-12.45
-8.55
-5.25
-1.95
1.50
4.35
7.20
10.05
13.35
16.65
19.95
23.10
26.40
29.55
32.55
35.55
38.55
41.40
44.25
47.10
49.80
52.35
54.90
57.30
59.70
61.95
64.05
66.30
68.25
70.20
72.00
73.65
75.30
76.80
78.30
79.65
80.85
81.90
82.95
83.85
84.75
85.50
86.10
86.55
87.00
87.45
87.60
87.75
87.75
87.75
87.60
87.30
87.00
86.55
85.95
85.35
84.60
83.70
82.80
81.75
80.55
79.35
78.00
76.50
75.00
73.35
71.70
69.75
67.95
65.85
63.75
61.50
59.25
56.85
54.45
51.90
49.35
46.65
43.80
40.95
38.10
35.10
32.10
28.95
25.95
22.65
19.50
16.20
13.05
9.75
6.90
4.05
1.05
-1.80
-5.10
-8.40
-11.70
-15.45
-19.20
-22.95
-26.55
-30.15
-33.60
-37.05
-40.35
-43.65
-46.80
-49.95
-52.80
-55.65
-58.50
-61.05
-63.60
-66.00
-68.25
-70.50
-72.45
-74.40
-76.20
-77.85
-79.35
-80.70
-81.90
-83.10
-84.15
-85.05
-85.80
-86.40
-86.85
-87.15
-87.45
-87.45
-87.45
-87.30
-87.00
-86.55
-85.95
-85.35
-84.45
-83.55
-82.50
-81.30
-79.95
-78.45
-76.95
-75.15
-73.35
-71.40
-69.30
-67.05
-64.65
-62.25
-59.70
-57.00
-54.15
-51.30
-48.30
-45.15
-41.85
-38.55
-35.25
-31.80
-28.20
-24.60
-21.00
-17.25
-13.65
-9.90
-6.60
-3.30
0.15
2.85
5.70
8.55
11.40
14.70
17.85
21.15
24.30
27.45
30.45
33.45
36.45
39.30
42.15
44.85
47.70
50.25
52.80
55.20
57.60
59.85
62.10
64.20
66.30
68.10
70.05
71.70
73.35
75.00
76.35
77.70
79.05
80.25
81.30
82.20
83.10
83.85
84.45
85.05
85.50
85.95
86.10
86.40
86.40
86.40
86.25
86.10
85.65
85.35
84.75
84.15
83.40
82.65
81.75
80.70
79.50
78.30
77.10
75.60
74.10
72.45
70.80
69.00
67.05
65.10
63.15
60.90
58.65
56.40
54.00
51.45
48.90
46.20
43.50
40.65
37.80
34.95
31.95
28.95
25.80
22.65
19.50
16.35
13.05
9.90
7.05
4.20
1.35
-1.50
-4.65
-7.95
-11.25
-15.00
-18.75
-22.35
-25.95
-29.40
-32.85
-36.30
-39.60
-42.75
-45.90
-49.05
-51.90
-54.75
-57.45
-60.15
-62.55
-64.95
-67.20
-69.30
-71.40
-73.20
-75.00
-76.65
-78.15
-79.50
-80.70
-81.90
-82.80
-83.70
-84.45
-85.05
-85.50
-85.80
-85.95
-86.10
-86.10
-85.80
-85.50
-85.05
-84.60
-83.85
-82.95
-82.05
-81.00
-79.65
-78.30
-76.95
-75.30
-73.65
-71.70
-69.75
-67.65
-65.40
-63.15
-60.60
-58.05
-55.35
-52.50
-49.65
-46.65
-43.50
-40.35
-37.05
-33.60
-30.15
-26.70
-23.10
-19.50
-15.90
-12.15
-8.55
-5.25
-1.95
1.35
4.05
6.90
9.75
12.45
15.75
18.90
22.05
25.05
28.20
31.20
34.20
37.05
39.90
42.60
45.30
48.00
50.55
53.10
55.35
57.75
60.00
62.10
64.20
66.15
67.95
69.75
71.40
73.05
74.55
75.90
77.10
78.30
79.50
80.55
81.30
82.20
82.95
83.55
84.00
84.45
84.75
84.90
85.05
85.05
84.90
84.75
84.45
84.15
83.55
83.10
82.35
81.60
80.70
79.65
78.60
77.55
76.20
74.85
73.35
71.85
70.20
68.40
66.60
64.65
62.55
60.45
58.35
55.95
53.70
51.15
48.75
46.05
43.35
40.65
37.80
34.95
32.10
29.10
25.95
22.95
19.80
16.65
13.50
10.20
7.05
4.20
1.50
-1.35
-4.50
-7.80
-11.10
-14.70
-18.30
-21.90
-25.50
-28.95
-32.40
-35.70
-39.00
-42.15
-45.30
-48.30
-51.15
-54.00
-56.70
-59.25
-61.65
-64.05
-66.30
-68.40
-70.35
-72.30
-73.95
-75.60
-77.10
-78.45
-79.65
-80.70
-81.60
-82.50
-83.10
-83.70
-84.15
-84.45
-84.60
-84.75
-84.60
-84.45
-84.15
-83.70
-83.10
-82.35
-81.45
-80.55
-79.35
-78.15
-76.80
-75.30
-73.65
-72.00
-70.05
-68.10
-66.00
-63.75
-61.35
-58.95
-56.40
-53.70
-50.85
-47.85
-44.85
-41.85
-38.70
-35.40
-32.10
-28.65
-25.05
-21.60
-18.00
-14.40
-10.80
-7.05
-3.90
-0.60
2.55
5.40
8.10
10.95
14.10
17.25
20.25
23.40
26.40
29.40
32.40
35.25
38.10
40.95
43.65
46.20
48.75
51.30
53.70
55.95
58.20
60.30
62.40
64.35
66.30
68.10
69.75
71.40
72.90
74.25
75.60
76.80
77.85
78.90
79.80
80.70
81.45
82.05
82.50
82.95
83.25
83.55
83.70
83.70
83.70
83.55
83.25
82.95
82.50
81.90
81.30
80.55
79.65
78.75
77.70
76.50
75.30
73.95
72.45
70.95
69.30
67.65
65.85
63.90
61.95
59.85
57.60
55.35
53.10
50.70
48.15
45.60
42.90
40.20
37.50
34.65
31.80
28.80
25.80
22.80
19.65
16.65
13.50
10.20
7.05
4.35
1.65
-1.20
-4.35
-7.50
-10.80
-14.40
-18.00
-21.45
-25.05
-28.50
-31.80
-35.10
-38.40
-41.55
-44.55
-47.55
-50.40
-53.25
-55.80
-58.35
-60.90
-63.15
-65.40
-67.35
-69.30
-71.25
-72.90
-74.55
-75.90
-77.25
-78.45
-79.50
-80.40
-81.30
-81.90
-82.50
-82.95
-83.25
-83.40
-83.40
-83.25
-83.10
-82.80
-82.35
-81.75
-81.00
-80.10
-79.05
-78.00
-76.65
-75.30
-73.80
-72.15
-70.50
-68.55
-66.60
-64.50
-62.25
-59.85
-57.30
-54.75
-52.05
-49.35
-46.35
-43.35
-40.35
-37.05
-33.90
-30.60
-27.15
-23.70
-20.25
-16.65
-13.05
-9.45
-6.30
-3.15
0.15
2.85
5.55
8.25
10.95
14.10
17.25
20.25
23.40
26.40
29.25
32.25
35.10
37.80
40.50
43.20
45.90
48.30
50.85
53.10
55.35
57.60
59.70
61.80
63.75
65.55
67.35
69.00
70.50
72.00
73.35
74.70
75.90
76.95
77.85
78.75
79.65
80.25
80.85
81.45
81.75
82.05
82.35
82.50
82.50
82.35
82.20
81.90
81.45
81.00
80.40
79.80
78.90
78.15
77.10
76.05
74.85
73.65
72.30
70.80
69.30
67.65
65.85
64.05
62.10
60.15
58.05
55.80
53.55
51.30
48.90
46.35
43.80
41.10
38.40
35.70
32.85
30.00
27.00
24.00
21.00
18.00
14.85
11.70
8.70
6.00
3.30
0.45
-2.25
-5.40
-8.55
-11.70
-15.30
-18.75
-22.20
-25.65
-29.10
-32.40
-35.70
-38.85
-41.85
-44.85
-47.85
-50.55
-53.25
-55.95
-58.35
-60.75
-63.00
-65.10
-67.05
-69.00
-70.80
-72.45
-73.95
-75.30
-76.50
-77.70
-78.75
-79.65
-80.40
-81.00
-81.45
-81.75
-82.05
-82.20
-82.05
-82.05
-81.75
-81.30
-80.70
-80.10];
Look at your data
First of all you should carefully look on your input data if your algorithm does not work as expected. Maybe it does what it is designed for but this is not what you expect. Some of your maxima are not clean local maxima. You have samples with exactly equal function values. I have drawn your data and magnified the first maximum to demonstrate it:
There are four values at index 165 to 169 that have identical numerical values. Your algorithm can not recognize a maximum of this shape.
Solutions
I have three suggestions for you.
Add precision to your data
Firstly: Look deeper in your data. They may have more precision if you take all significant digits. With a closer look your peaks might have real local maxima.
Don't re-invent the wheel
If you can solve it in matlab/octave you could just use an existing solution already able to deal with complicated situation as this:
[J,K]=findpeaks(fun,'DoubleSided')
This will give the expected result:
J =
-1.5603
1.5499
-1.5315
1.5263
-1.5080
1.5027
-1.4844
1.4792
-1.4608
1.4556
-1.4399
1.4347
K =
83
165
249
332
415
499
581
664
745
827
909
991
Use an improved algorithm
If you need to implement this method yourself you have to adapt your criterion for peak finding. For example you could use two single sided criteria and mark raising and falling and flat areas:
c(i)=1*(fun(i-1) < fun(i)) + -1*(fun(i+1) < fun(i))
This expression will produce in matlab/octave a 1 value for raising signal parts, 0 for flat parts and -1 for falling parts.
Now you can search this array for some conditions:
If you find a place without raise or fall after a raise and before falling signal you found a maximum. You also find a maximum if a fall follows a raise immediately.

Android things lcd config

I'm trying to get a 5" LCD working with my raspberry pi 3 and Android Things Developer Preview 4.1.
I've added this to my config.txt:
max_usb_current=1
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_cvt 800 480 60 6 0 0 0
All I get is a white screen with some artifacts:
It's not a cable issue, I can use the screen with my Windows PC just fine.
I've found some maybe relevant lines in logcat:
01-01 00:00:19.529 412-412/? I/SystemServiceManager: Starting com.android.server.display.DisplayManagerService
01-01 00:00:19.568 412-434/? I/DisplayManagerService: Display device added: DisplayDeviceInfo{"Built-in Screen": uniqueId="local:0", 800 x 480, modeId 1, defaultModeId 1, supportedModes [{id=1, width=800, height=480, fps=60.000004}], colorTransformId 1, defaultColorTransformId 1, supportedColorTransforms [{id=1, colorTransform=0}], HdrCapabilities android.view.Display$HdrCapabilities#192777c, density 160, 160.0 x 160.42105 dpi, appVsyncOff 0, presDeadline 17666666, touch INTERNAL, rotation 0, type BUILT_IN, state UNKNOWN, FLAG_DEFAULT_DISPLAY, FLAG_ROTATES_WITH_CONTENT, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS}
01-01 00:00:19.571 412-434/? I/DisplayManagerService: Display device changed state: "Built-in Screen", ON
01-01 00:00:23.990 412-434/? I/WindowManager: No existing display settings /data/system/display_settings.xml; starting empty
I've bought the screen from an ebay seller. It came with a dvd, and had a sample config.txt file, it suggests the same settings.
What am I doing wrong?

POS tagging in Scala

I tried to POS tag a sentence in Scala using Stanford parser like below
val lp:LexicalizedParser = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
lp.setOptionFlags("-maxLength", "50", "-retainTmpSubcategories")
val s = "I love to play"
val parse :Tree = lp.apply(s)
val taggedWords = parse.taggedYield()
println(taggedWords)
I got an error type mismatch; found : java.lang.String required: java.util.List[_ <: edu.stanford.nlp.ling.HasWord] in the line val parse :Tree = lp.apply(s)
I don't know whether this is the right way of doing it or not. Are there any other easy ways of POS tagging a sentence in Scala?
You might like to consider the FACTORIE toolkit (http://github.com/factorie/factorie). It is a general library for machine learning and graphical models that happens to include an extensive suite of natural language processing components (tokenization, token normalization, morphological analysis, sentence segmentation, part-of-speech tagging, named entity recognition, dependency parsing, mention finding, coreference).
Furthermore it is written entirely in Scala, and it is released under the Apache License.
Documentation is currently sparse, but will be improving in the coming months.
For example, once Maven-based installation is finished you can type at the command line:
bin/fac nlp --pos1 --parser1 --ner1
to launch a socket-listening multi-threaded NLP server. Then query it by piping plain text to its socket number:
echo "Mr. Jones took a job at Google in New York. He and his Australian wife moved from New South Wales on 4/1/12." | nc localhost 3228
The output is then
1 1 Mr. NNP 2 nn O
2 2 Jones NNP 3 nsubj U-PER
3 3 took VBD 0 root O
4 4 a DT 5 det O
5 5 job NN 3 dobj O
6 6 at IN 3 prep O
7 7 Google NNP 6 pobj U-ORG
8 8 in IN 7 prep O
9 9 New NNP 10 nn B-LOC
10 10 York NNP 8 pobj L-LOC
11 11 . . 3 punct O
12 1 He PRP 6 nsubj O
13 2 and CC 1 cc O
14 3 his PRP$ 5 poss O
15 4 Australian JJ 5 amod U-MISC
16 5 wife NN 6 nsubj O
17 6 moved VBD 0 root O
18 7 from IN 6 prep O
19 8 New NNP 9 nn B-LOC
20 9 South NNP 10 nn I-LOC
21 10 Wales NNP 7 pobj L-LOC
22 11 on IN 6 prep O
23 12 4/1/12 NNP 11 pobj O
24 13 . . 6 punct O
Of course there is a programmatic API to all this functionality as well.
import cc.factorie._
import cc.factorie.app.nlp._
val doc = new Document("Education is the most powerful weapon which you can use to change the world.")
DocumentAnnotatorPipeline(pos.POS1).process(doc)
for (token <- doc.tokens)
println("%-10s %-5s".format(token.string, token.posLabel.categoryValue))
will output:
Education NN
is VBZ
the DT
most RBS
powerful JJ
weapon NN
which WDT
you PRP
can MD
use VB
to TO
change VB
the DT
world NN
. .
I found a very simple way to do POS tagging in Scala
Step 1
Download stanford tagger version 3.2.0 form the link below
http://nlp.stanford.edu/software/stanford-postagger-2013-06-20.zip
Step 2
Add stanford-postagger jar present in the folder to your project and also place the english-left3words-distsim.tagger file present in the models folder in your project
Then, with the code below you can pos tag a sentence in Scala
val tagger = new MaxentTagger(
"english-left3words-distsim.tagger")
val art_con = "My name is Rahul"
val tagged = tagger.tagString(art_con)
println(tagged)
Output: My_PRP$ name_NN is_VBZ Rahul_NNP
I believe the API of the Stanford Parser has changed somewhat, as it does sometimes. apply has the signature, public Tree apply(java.util.List<? extends HasWord> words), and this is what you see in the error message.
What you should use now is parse, which has the signature public Tree parse(java.lang.String sentence).