VBA parse JSON empty data - json

I'm trying to parse some data to a sheet with VBA. My code work's fine when all data in the JSON are provided, but when there is no (team1)(name) or (team1)(id), I get an error of incompatible data.
The code is below! It wrote 3 or 4 lines of data before the error.
The JSON data is more below.
IS there any way to avoid registers that don’t have all data or just write an “empty” value when the data is null?
Dim jsonText As String
Dim jsonObject As Object, item As Object
Dim i As Long
Dim ws As Worksheet
Set ws = Worksheets("Matchs")
jsonText = ws.Cells(1, 1)
Dim http As Object, JSON As Object
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", "getMatches.json", False
http.Send
Set JSON = ParseJson(http.responseText)
i = 2
For Each item In JSON
ws.Cells(i, 1) = item("id")
ws.Cells(i, 2) = item("date")
ws.Cells(i, 3) = item("title")
ws.Cells(i, 5) = item("team1")("name")
ws.Cells(i, 6) = item("team1")("id")
i = i + 1
Next
The JSON =>
[{"id":2342835,"date":1594731600000,
"team1":{"name":"FATE","id":9863},
"team2":{"name":"Budapest Five","id":9802},
"format":"bo1",
"event":{"name":"Eden Arena Malta Vibes Cup 3","id":5426},
"stars":0,"live":false},
{"id":2342836,"date":1594731600000,
"team1":{"name":"PACT","id":8248},
"team2":{"name":"Singularity","id":6978},
"format":"bo1",
"event":{"name":"Eden Arena Malta Vibes Cup 3","id":5426},
"stars":0,"live":false},
{"id":2342843,"date":1594735200000,
"title":"Malta Vibes 3 - Group A Winners' Match",
"stars":0,"live":false},
{"id":2342862,"date":1594735200000,
"team1":{"name":"Nexus","id":7187},
"team2":{"name":"BIG Academy","id":10254},"format":"bo3","event":{"name":"Betano Masters Europe 2020","id":5427},"stars":0,"live":false},{"id":2342834,"date":1594746000000,"team1":{"name":"sAw","id":10567},"team2":{"name":"Nexus","id":7187},"format":"bo3","event":{"name":"ESEA Advanced Season 34 Europe","id":5415},"stars":1,"live":false},{"id":2342844,"date":1594746000000,"title":"Malta Vibes 3 - Group A Elimination Match","stars":0,"live":false},{"id":2342863,"date":1594750500000,"team1":{"name":"Unicorns of Love","id":9812},"team2":{"name":"Giants","id":4949},"format":"bo3","event":{"name":"Betano Masters Europe 2020","id":5427},"stars":0,"live":false},{"id":2342801,"date":1594751400000,"team1":{"name":"Secret","id":10488},"team2":{"name":"Tricked","id":4602},"format":"bo3","event":{"name":"ESEA Advanced Season 34 Europe","id":5415},"stars":0,"live":false},{"id":2342845,"date":1594756800000,"title":"Malta Vibes 3 - Group A Decider Match","stars":0,"live":false},{"id":2342803,"date":1594774800000,"team1":{"name":"Thunder Logic","id":9615},"team2":{"name":"RBG","id":10258},"format":"bo3","event":{"name":"ESEA Advanced Season 34 North America","id":5416},"stars":0,"live":false},{"id":2342864,"date":1594776600000,"team1":{"name":"Third Impact","id":10469},"team2":{"name":"Lethal Divide","id":10770},"format":"bo3","event":{"name":"ESEA Advanced Season 34 North America","id":5416},"stars":0,"live":false},{"id":2342816,"date":1594796400000,"team1":{"name":"Hard Legion","id":10421},"team2":{"name":"AGF","id":8704},"format":"bo3","event":{"name":"Nine to Five 1","id":5409},"stars":0,"live":false},{"id":2342817,"date":1594796400000,"team1":{"name":"Gambit Youngsters","id":9976},"team2":{"name":"ALTERNATE aTTaX","id":4501},"format":"bo3","event":{"name":"Nine to Five 1","id":5409},"stars":0,"live":false},{"id":2342818,"date":1594807200000,"title":"Nine to Five 1 Grand Final","stars":0,"live":false},{"id":2342837,"date":1594818000000,"team1":{"name":"HellRaisers","id":5310},"team2":{"name":"HONORIS","id":10737},"format":"bo1","event":{"name":"Eden Arena Malta Vibes Cup 3","id":5426},"stars":0,"live":false},{"id":2342838,"date":1594818000000,"team1":{"name":"AGF","id":8704},"team2":{"name":"CR4ZY","id":10150},"format":"bo1","event":{"name":"Eden Arena Malta Vibes Cup 3","id":5426},"stars":0,"live":false},{"id":2342846,"date":1594821600000,"title":"Malta Vibes 3 - Group B Winners' Match","stars":0,"live":false},{"id":2342847,"date":1594832400000,"title":"Malta Vibes 3 - Group B Elimination Match","stars":0,"live":false},{"id":2342848,"date":1594843200000,"title":"Malta Vibes 3 - Group B Decider Match","stars":0,"live":false},{"id":2342532,"date":1594890000000,"team1":{"name":"Rooster","id":9881},"team2":{"name":"Paradox","id":7983},"format":"bo3","event":{"name":"LPL Pro League Season 5","id":5319},"stars":0,"live":false},{"id":2342839,"date":1594893600000,"team1":{"name":"Gambit Youngsters","id":9976},"team2":{"name":"Lyngby Vikings","id":8963},"format":"bo1","event":{"name":"Eden Arena Malta Vibes Cup 3","id":5426},"stars":0,"live":false},{"id":2342840,"date":1594897200000,"team1":{"name":"Illuminar","id":8813},"team2":{"name":"AVEZ","id":9797},"format":"bo1","event":{"name":"Eden Arena Malta Vibes Cup 3","id":5426},"stars":0,"live":false},{"id":2342800,"date":1594899000000,"team1":{"name":"Mako","id":10507},"team2":{"name":"TRUCKERS WITH ATTITUDE","id":10713},"format":"bo3","event":{"name":"LPL Pro League Season 5","id":5319},"stars":0,"live":false},{"id":2342849,"date":1594900800000,"title":"Malta Vibes 3 - Group C Winners' Match","stars":0,"live":false},{"id":2342850,"date":1594911600000,"title":"Malta Vibes 3 - Group C Elimination Match","stars":0,"live":false},{"id":2342851,"date":1594922400000,"title":"Malta Vibes 3 - Group C Decider Match","stars":0,"live":false},{"id":2342824,"date":1594962000000,"team1":{"name":"Invictus","id":7966},"team2":{"name":"D13","id":8607},"format":"bo3","event":{"name":"Perfect World Asia League Summer 2020","id":5376},"stars":0,"live":false},{"id":2342825,"date":1594971000000,"team1":{"name":"ViCi","id":7606},"team2":{"name":"Lucid Dream","id":8680},"format":"bo3","event":{"name":"Perfect World Asia League Summer 2020","id":5376},"stars":0,"live":false},{"id":2342826,"date":1594980000000,"team1":{"name":"TYLOO","id":4863},"team2":{"name":"Divine Vendetta","id":10396},"format":"bo3","event":{"name":"Perfect World Asia League Summer 2020","id":5376},"stars":0,"live":false},{"id":2342841,"date":1594980000000,"team1":{"name":"Hard Legion","id":10421},"team2":{"name":"SG.pro","id":10105},"format":"bo1","event":{"name":"Eden Arena Malta Vibes Cup 3","id":5426},"stars":0,"live":false},{"id":2342842,"date":1594983600000,"team1":{"name":"ALTERNATE aTTaX","id":4501},"team2":{"name":"Syman","id":8772},"format":"bo1","event":{"name":"Eden Arena Malta Vibes Cup 3","id":5426},"stars":0,"live":false},{"id":2342852,"date":1594987200000,"title":"Malta Vibes 3 - Group D Winners' Match","stars":0,"live":false},{"id":2342827,"date":1594989000000,"team1":{"name":"TIGER","id":10661},"team2":{"name":"Beyond","id":8262},"format":"bo3","event":{"name":"Perfect World Asia League Summer 2020","id":5376},"stars":0,"live":false},{"id":2342853,"date":1594998000000,"title":"Malta Vibes 3 - Group D Elimination Match","stars":0,"live":false},{"id":2342854,"date":1595008800000,"title":"Malta Vibes 3 - Group D Decider Match","stars":0,"live":false},{"id":2342855,"date":1595059200000,"title":"Malta Vibes 3 - Quarter-Final #1","stars":0,"live":false},{"id":2342828,"date":1595062800000,"title":"PAL Summer - Semi-final #1","stars":0,"live":false},{"id":2342856,"date":1595070000000,"title":"Malta Vibes 3 - Quarter-Final #2","stars":0,"live":false},{"id":2342829,"date":1595073600000,"title":"PAL Summer - Semi-final #2","stars":0,"live":false},{"id":2342857,"date":1595080800000,"title":"Malta Vibes 3 - Quarter-Final #3","stars":0,"live":false},{"id":2342858,"date":1595091600000,"title":"Malta Vibes 3 - Quarter-Final #4","stars":0,"live":false},{"id":2342830,"date":1595149200000,"title":"PAL Summer - 3rd Place Decider","stars":0,"live":false},{"id":2342859,"date":1595152800000,"title":"Malta Vibes 3 - Semi-Final #1","stars":0,"live":false},{"id":2342831,"date":1595160000000,"title":"PAL Summer - Grand Final","stars":0,"live":false},{"id":2342860,"date":1595163600000,"title":"Malta Vibes 3 - Semi-Final #2","stars":0,"live":false},{"id":2342861,"date":1595174400000,"title":"Malta Vibes 3 - Grand Final","stars":0,"live":false},{"id":2342643,"date":1597134600000,"team1":{"name":"Ground Zero","id":8536},"team2":{"name":"Paradox","id":7983},"format":"bo3","event":{"name":"ESL Australia & NZ Championship Season 11","id":5318},"stars":0,"live":false},{"id":2342520,"date":1597147200000,"team1":{"name":"Bantz","id":10712},"team2":{"name":"TRUCKERS WITH ATTITUDE","id":10713},"format":"bo3","event":{"name":"ESL Australia & NZ Championship Season 11","id":5318},"stars":0,"live":false}]

You can use the dictionary Exists method:
If item.Exists("team1") Then
If item("team1").Exists("name") Then
'record the name
End If
End If

Related

Problem with web scraping of required content from a URL link in R

I am using a script to scrape the required content from a link in which there are different subjects.
library(rvest)
url <- "https://ssb.bannerprod.memphis.edu/prod/bwckschd.p_get_crse_unsec"
query <- list(term_in = "202110", sel_subj = "dummy", sel_day = "dummy",
sel_schd = "dummy", sel_insm = "dummy", sel_camp = "dummy",
sel_levl = "dummy", sel_sess = "dummy", sel_instr = "dummy",
sel_ptrm = "dummy", sel_attr = "dummy", sel_subj = "ARCH",
sel_crse = "", sel_title = "", sel_insm = "%",
sel_from_cred = "", sel_to_cred = "", sel_camp = "%",
sel_levl = "%", sel_ptrm = "%", sel_instr = "%",
sel_attr = "%", begin_hh = "0", begin_mi = "0",
begin_ap = "a", end_hh = "0", end_mi = "0",
end_ap = "a")
In the above query sel_subj changes for every different subjects
html <- read_html(httr::POST(url, body = query))
classes <- html %>% html_nodes(xpath = "//th/a") %>% html_text()
instructor_nodes <- html %>%
html_nodes(xpath = "//td[#class='dddefault']/a[contains(#href, 'mailto')]")
instructors <- html_attr(instructor_nodes, "target")
emails <- html_attr(instructor_nodes, "href")
length(classes)
[1] 32
length(instructors)
[1] 39
length(emails)
[1] 39
sq <- seq(max(length(classes), length(instructors), length(emails)))
data.frame(classes[sq], instructors[sq], emails[sq])
And the result looks like below which is wrong:
classes.sq. instructors.sq. emails.sq.
1 Fundamentals of Design Studio - 23838 - ARCH 1111 - 001 Jennifer L. Thompson mailto:jlthmps5#memphis.edu
2 Fundamentals of Design Studio - 23839 - ARCH 1111 - 002 Pamela J. Hurley mailto:pjhurley#memphis.edu
3 Design Visualization - 11107 - ARCH 1113 - 001 Michael K. Chisamore mailto:mkchsmre#memphis.edu
4 Design Visualization - 18386 - ARCH 1113 - 002 Michael K. Chisamore mailto:mkchsmre#memphis.edu
5 History of Architecture 1 - 23218 - ARCH 1211 - 001 Pamela J. Hurley mailto:pjhurley#memphis.edu
6 Building Technology 2 - 23840 - ARCH 2412 - 001 Marika E. Snider mailto:mesnider#memphis.edu
7 Computer Apps in Design 2 - 11111 - ARCH 2612 - 001 Timothy E. Michael mailto:tmichael#memphis.edu
8 Design Studio 2 - 11112 - ARCH 2712 - 001 Timothy E. Michael mailto:tmichael#memphis.edu
9 Design Studio 2 - 15408 - ARCH 2712 - 002 Andrew M. Parks mailto:amparks#memphis.edu
10 Survey of Interiors+Furniture - 25734 - ARCH 3213 - 001 Andrew M. Parks mailto:amparks#memphis.edu
11 Determinants of Modern Design - 27436 - ARCH 3221 - 001 Michael D. Hagge mailto:mdhagge#memphis.edu
12 Structural Design 2 - 23837 - ARCH 3322 - 001 Michael D. Hagge mailto:mdhagge#memphis.edu
13 Professional Practice - 25097 - ARCH 3431 - 001 Andrew M. Parks mailto:amparks#memphis.edu
14 Design Studio 4 - 11115 - ARCH 3714 - 001 Sonia Raheel mailto:sraheel#memphis.edu
15 Design Studio 4 - 23221 - ARCH 3714 - 002 Pamela J. Hurley mailto:pjhurley#memphis.edu
16 Architecture Independent Study - 11117 - ARCH 4021 - 201 Jennifer L. Barker mailto:jlbrker1#memphis.edu
17 Sustainable Design - 19491 - ARCH 4421 - 001 Jennifer L. Barker mailto:jlbrker1#memphis.edu
18 Internship in Architecture - 21000 - ARCH 4430 - 001 Marika E. Snider mailto:mesnider#memphis.edu
19 Design Studio 6 - 11134 - ARCH 4716 - 001 Pamela J. Hurley mailto:pjhurley#memphis.edu
20 Sustainable Design - 19492 - ARCH 6421 - 001 Marika E. Snider mailto:mesnider#memphis.edu
21 Advanced Design Seminar 2 - 18387 - ARCH 7012 - 001 Marika E. Snider mailto:mesnider#memphis.edu
22 Contemporary Architecture 2 - 24104 - ARCH 7222 - 001 Pamela J. Hurley mailto:pjhurley#memphis.edu
23 Internship in Architecture - 19495 - ARCH 7430 - 001 Jennifer L. Barker mailto:jlbrker1#memphis.edu
24 Adv Professional Practice - 19496 - ARCH 7431 - 001 Jennifer L. Thompson mailto:jlthmps5#memphis.edu
25 Advanced Design Studio 2 - 18389 - ARCH 7712 - 001 Michael D. Hagge mailto:mdhagge#memphis.edu
26 Architecture Research - 25098 - ARCH 7930 - 001 Brian D. Andrews mailto:bdndrews#memphis.edu
27 Architecture Thesis Studio - 19499 - ARCH 7996 - 003 Jennifer L. Thompson mailto:jlthmps5#memphis.edu
28 Architecture Thesis Studio - 19500 - ARCH 7996 - 004 Brian D. Andrews mailto:bdndrews#memphis.edu
29 Architecture Thesis Studio - 19501 - ARCH 7996 - 005 Andrew M. Parks mailto:amparks#memphis.edu
30 Architecture Thesis Studio - 19502 - ARCH 7996 - 006 Michael D. Hagge mailto:mdhagge#memphis.edu
31 Architecture Thesis Studio - 19503 - ARCH 7996 - 007 Brian D. Andrews mailto:bdndrews#memphis.edu
32 Architecture Thesis Studio - 20972 - ARCH 7996 - 008 Michael K. Chisamore mailto:mkchsmre#memphis.edu
33 <NA> Pamela J. Hurley mailto:pjhurley#memphis.edu
34 <NA> Jennifer L. Barker mailto:jlbrker1#memphis.edu
35 <NA> Michael K. Chisamore mailto:mkchsmre#memphis.edu
36 <NA> Pamela J. Hurley mailto:pjhurley#memphis.edu
37 <NA> Jennifer L. Thompson mailto:jlthmps5#memphis.edu
38 <NA> Brian D. Andrews mailto:bdndrews#memphis.edu
39 <NA> Marika E. Snider mailto:mesnider#memphis.edu
But in the link, the data looks different.
For example:
There are few classes without any instructor and email (It is mentioned TBA) like below:
And there are few other classes that have two/three/four/multiple instructors.
And there are few other classes with the same instructor given multiple times like below:
For such data I want my output to be looked like below:
classes.sq. instructors.sq. emails.sq.
1 Fundamentals of Design Studio - 23838 - ARCH 1111 - 001 Jennifer L. Thompson mailto:jlthmps5#memphis.edu
2 Fundamentals of Design Studio - 23839 - ARCH 1111 - 002 TBA
3 Design Visualization - 11107 - ARCH 1113 - 001 Michael K. Chisamore,Pamela J. Hurley mailto:mkchsmre#memphis.edu,pjhurley#memphis.edu
4 Design Visualization - 18386 - ARCH 1113 - 002 Pamela J. Hurley,Michael K. Chisamore mailto:pjhurley#memphis.edu,mkchsmre#memphis.edu
5 History of Architecture 1 - 23218 - ARCH 1211 - 001 Marika E. Snider mailto:mesnider#memphis.edu
6 Building Technology 2 - 23840 - ARCH 2412 - 001 Timothy E. Michael mailto:tmichael#memphis.edu
P.S. if the posted URL link doesn't work. Please follow this:
In this link `https://ssb.bannerprod.memphis.edu/prod/bwckschd.p_disp_dyn_sched`
Select by term -> Spring Term 2021 (view only) -> Submit
Subject -> select ARCH Architecture -> scroll down and click Class Search
How to deal with missing data (TBA), multiple instructors, and the same instructor given multiple times?
The problem is with using the html_nodes() function. This function will return a list of values without any regard to which node the value was found. Since you webpage will have sometime have multiple instructors per class or none, a more targeted approach is needed.
In this code block we first find each of the class nodes which contain all of the information we want. Then we parse each of those node individually (inside the lapply function) to extract the instructors and email also checking for empty fields. There is a single line in each data frame for each instructor, so some data frame will have multiple lines if there are multiple instructors.
We assemble a list of data frames (bind_rows) for each class and then merge the instructor and email results for the same class
library(rvest)
library(dplyr)
url <- "https://ssb.bannerprod.memphis.edu/prod/bwckschd.p_get_crse_unsec"
query <- list(term_in = "202110", sel_subj = "dummy", sel_day = "dummy",
sel_schd = "dummy", sel_insm = "dummy", sel_camp = "dummy",
sel_levl = "dummy", sel_sess = "dummy", sel_instr = "dummy",
sel_ptrm = "dummy", sel_attr = "dummy", sel_subj = "ARCH",
sel_crse = "", sel_title = "", sel_insm = "%",
sel_from_cred = "", sel_to_cred = "", sel_camp = "%",
sel_levl = "%", sel_ptrm = "%", sel_instr = "%",
sel_attr = "%", begin_hh = "0", begin_mi = "0",
begin_ap = "a", end_hh = "0", end_mi = "0",
end_ap = "a")
html <- read_html(httr::POST(url, body = query))
classes <- html %>% html_nodes("th.ddtitle") %>% html_text()
classinfo <- html %>% html_nodes("tr td.dddefault")
classinfo <- html %>% html_nodes(xpath = ".//tr/td[#class='dddefault']")
classinfo <- classinfo[nchar( html_text(classinfo))>50 ] #eliminate the extra found nodes
classlink <- classinfo %>% html_nodes("a") %>% html_attr("href") #find all links
classlinktext <- classinfo %>% html_nodes("a") %>% html_text() #find the link text
classlink <- classlink[classlinktext=="View Catalog Entry"] #keep only the links for "View Catalog Entry"
dfs <-lapply(1:length(classinfo), function(i) {
# classname <-classes[i] %>% html_node(xpath = ".//a") %>% html_text()
instructor_node <- classinfo[i] %>% html_nodes("table.datadisplaytable") %>%
html_nodes(xpath = ".//a[contains(#href, 'mailto')]")
instructors <- html_attr(instructor_node, "target")
emails <- html_attr(instructor_node, "href")
#check to see if instructor was assign if not TBD
if(length(instructors)==0){
instructors <- "TBD"
emails <- "NA"
}
data.frame(classname=classes[i], link=classlink[i], instructors, emails)
})
#merge list into data frame
answer<- bind_rows(dfs)
#consolidation the instructions in the same class
finalanswer<-answer %>% group_by(classes) %>% summarize(instructors2 = paste(instructors, collapse = ", "), emails = paste(emails, collapse = ", "))
# the paste(instructors, collapse = ", ") could be contained within the lapply
# loop but adding it here add some flexibility depending on whether
# answer or final answer is the end result.
head(finalanswer, 16)
tail(finalanswer, 16)

SQL query written in ASP.NET (code behind is VB) not providing results expected

Below is a portion of my code behind in an ASP.NET app, the code behind is visual basic. When providerOfficeQuery is run it is not providing the expected results. You can see the portion of the database that the query is using:
67 RUMINJO, ANNE MD CHAPEL HILL - PROVIDENCE RD chapelhillProvidenceRDArrayList
68 RUSSO, FRANK FNP-BC ASHEVILLE - RIDGEFIELD BLVD ashevilleRidgefieldBLVDArrayList
69 SAWYER, LOUIS PHD DURHAM COUNSELING CENTER durhamCounselingCenterArrayList
70 SAWYER, LOUIS PHD DURHAM - SHANNON RD durhamShannonRDArrayList
71 SCHIAPPA, JENNIFER LCSW CARY COUNSELING CENTER caryCounselingCenterArrayList
I'm sorry for the formatting, the fields are ID, PROVIDER, OFFICE, OFFICE_ARRAY_LIST respectively.
When providerName equals "SAWYER, LOUIS PHD", I expect the query to produce two results, both row 69 and 70 and subsequently to provide me with office "DURHAM COUNSELING CENTER" and "DURHAM - SHANNON RD", yet when the query is run what actually occurs is that I end up with "DURHAM COUNSELING CENTER" twice. I have verified this with adding the results to a ListBox to verify the results.
I'm not an expert and I have scoured Google and various forums and cannot find why this isn't producing the expected results. Any thoughts, anyone?
Thanks.
' find the Provider's office and add it to the ListBox
Dim providerOfficeQuery = From populateItem In db.Sheet3_
Where populateItem.PROVIDER = providerName
Select populateItem
For Each x In providerOfficeQuery
providerInfoOffice = x.OFFICE
If providerInfoOffice = "ASHEVILLE - DOCTOR'S PARK" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS OF CENTRAL ASHEVILLE")
ElseIf providerInfoOffice = "ASHEVILLE - RIDGEFIELD BLVD" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS OF SOUTH ASHEVILLE")
ElseIf providerInfoOffice = "CARY - E CHATHAM ST" Then
providerInfoListBox.Items.Add("CPMH AFFILIATE: CARY - DONNA PARRISH")
ElseIf providerInfoOffice = "CARY - KILDAIRE FARM RD" Then
providerInfoListBox.Items.Add("CPMH AFFILIATE: CARY - JENNY TART")
ElseIf providerInfoOffice = "CARY - SE CARY PKWY" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS OF CARY")
ElseIf providerInfoOffice = "CARY COUNSELING CENTER" Then
providerInfoListBox.Items.Add("CARY COUNSELING CENTER")
ElseIf providerInfoOffice = "CHAPEL HILL - FRANKLIN ST" Then
providerInfoListBox.Items.Add("CPMH AFFILIATE: CHAPEL HILL - DANA BENNISON")
ElseIf providerInfoOffice = "CHAPEL HILL - PROVIDENCE RD" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS Of CHAPEL HILL")
ElseIf providerInfoOffice = "CHARLOTTE" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS OF CONCORD")
ElseIf providerInfoOffice = "DURHAM - BROAD ST" Then
providerInfoListBox.Items.Add("CPMH AFFILIATE: DURHAM - SARAH DAWSON")
ElseIf providerInfoOffice = "DURHAM - NEW HOPE COURT" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS AT NEW HOPE COURT")
ElseIf providerInfoOffice = "DURHAM - SHANNON RD" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS AT SHANNON RD")
ElseIf providerInfoOffice = "DURHAM COUNSELING CENTER" Then
providerInfoListBox.Items.Add("DURHAM COUNSELING CENTER")
ElseIf providerInfoOffice = "NORTH RALEIGH COUNSELING CENTER" Then
providerInfoListBox.Items.Add("NORTH RALEIGH COUNSELING CENTER")
ElseIf providerInfoOffice = "RALEIGH - DRESSER COURT" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS OF RALEIGH")
ElseIf providerInfoOffice = "RALEIGH - NEUROPSYCH CLINIC" Then
providerInfoListBox.Items.Add("THE NEUROPSYCH CLINIC")
ElseIf providerInfoOffice = "RALEIGH - RALEIGH ANNEX" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS RALEIGH ANNEX")
ElseIf providerInfoOffice = "RALEIGH - WELLNESS CENTER" Then
providerInfoListBox.Items.Add("THE WELLNESS CENTER")
ElseIf providerInfoOffice = "WAKE FOREST - CAPCOM AVE" Then
providerInfoListBox.Items.Add("CAROLINA PARTNERS OF WAKE FOREST")
ElseIf providerInfoOffice = "WAKE FOREST - WFCC" Then
providerInfoListBox.Items.Add("WAKE FOREST COUNSELING CENTER")
ElseIf providerInfoOffice = "WILSON - NASH ST" Then
providerInfoListBox.Items.Add("WILSON PSYCHIATRIC ASSOCIATES A CAROLINA PARTNERS PRACTICE")
End If
providerInfoOffice = Nothing
Next
Try adding:
Dim ResultCount = provierOfficeQuery.Count()
and outputting that value of ResultCount for the "DURHAM COUNSELING CENTER" case to make sure that you are actually getting the two results returned.
If it is not two, then you have to look at your source data as mentioned by Zaki. For example, one of the records for SAWYER, LOUIS PHD may have an extra space or something in the PROVIDER field.

customized JSON output in pig

Need customized JSON output--
(I have two files - text file and schema file)
abc.txt -
100002030,Tom,peter,eng,block 3, lane 5,california,10021
100003031,Tom,john,doc,block 2, lane 2,california,10021
100004032,Tom,jim,eng,block 1, lane 1,california,10021
100005033,Tom,trek,doc,block 2, lane 2,california,10021
100006034,Tom,peter,eng,block 6, lane 6,california,10021
abc_schema.txt (field name and position)
rollno 1
firstname 2
lastname 3
qualification 4
address1 5
address2 6
city 7
Zipcode 8
Rules-
First 6 characters of rollno
Need to club address1 | address2 | city
Prefix Address to above
Expected Output-
{"rollno":"100002","firstname":"Tom","lastname:"peter","qualification":"eng","Address":"block 3 lane 5 california","zipcode":"10021"}
{"rollno":"100002","firstname":"Tom","lastname:"john","qualification":"doc","Address":"block 2 lane 2 california","zipcode":"10021"}
{"rollno":"100004","firstname":"Tom","lastname:"jim","qualification":"eng","Address":"block 1 lane 1 california","zipcode":"10021"}
{"rollno":"100005","firstname":"Tom","lastname:"trek","qualification":"doc","Address":"block 2 lane 2 california","zipcode":"10021"}
{"rollno":"100006","firstname":"Tom","lastname:"peter","qualification":"eng","Address":"block 6 lane 6 california","zipcode":"10021"}
I do not wish to hardcode the fields but read from the schema file, the idea is to have reusable code. Something like looping schema file and the text file
A = load 'abc.txt' using PigStorage(',') as (rollno, Fname,Lname,qua,add1,add2,city,Zipcode);
B = foreach A generate rollno, Fname,Lname,qua,concate (add1,add2,city) ,Zipcode;
C= STORE B
INTO 'first_table.json'
USING JsonStorage();
Hope this helps.

Hide Java output in HTML file

I write this code in scala.html to show the MySQL data in an HTML table:
#for(a <- 1 to rowNum){
#rs.next()
<tr>
<td>#rs.getString("building_id")</td>
<td>#rs.getString("building_name")</td>
<td>#rs.getString("building_type")</td>
<td>#rs.getString("address")</td>
</tr>
It gives the following result:
true true true true true true true true true true
id name type address
1 The Floravale condo Westwood Avenue
2 building2 condo Jurong West Street 21
3 building3 hdb Jurong West Street 31
4 building4 hdb Jurong West Street 81
5 building5 hdb Jurong West Street 61
6 building6 hdb Jurong West Street 81
7 building7 hdb Kang Ching Road
8 building8 hdb Kang Ching Road
9 building9 hdb Boon Lay Drive
10 building10 hdb Boon Lay Place
How can I hide the true as the output of #rs.next()?
Or are there other ways to display data? Thanks!
As commented, it is probably that true is being returned, and therefore appearing as a result. A more typical usage would be to collect your rows in a List passed to the view, often in it's own case class (say Building), then use a map:
#buildings.map { building =>
<td>building.id</td>
<td>building.name</td>
...
}

How to match and assign data the pythonic way?

I have a list (mysql table) of People and their titles as shown in the table below. I also have a list of titles and their categories. How do I assign their categories to the person? The problem arises when there are multiple titles for a person. What is the pythonic way of mapping the title to the category and assigning it to the person?
People Table
Name Title
--------------------
John D CEO, COO, CTO
Mary J COO, MD
Tim C Dev Ops, Director
Title Category table
Title Executive IT Other
-----------------------------
CEO 1
COO 1
CTO 1 1
MD 1
Dev Ops 1
Director 1
Desired output :
Name Title Executive IT Other
---------------------------------------------
John D CEO, COO, CTO 1 1
Mary J COO, MD 1
Tim C Dev Ops, Director 1 1
name_title = (("John D",("CEO","COO","CTO")),
("Mary J",("COO","MD")),
("Tim C",("Dev Ops","Director")))
title_cat = {"CEO": set(["Executive"]),
"COO": set(["Executive"]),
"CTO": set(["Executive"]),
"MD": set(["Executive"]),
"Dev Ops": set(["IT"]),
"Director": set(["Other"])}
name_cat = [(name, reduce(lambda x,y:x|y, [title_cat[title]for title in titles])) for name,titles in name_title]
It would be nice if there was a union which behaved like sum on sets.
people=['john','Mary','Tim']
Title=[['CEO','COO','CTO'],['COO','MD'],['DevOps','Director']]
title_des={'CEO':'Executive','COO':'Executive','CTO':'Executive',
'MD':'Executive','DevOps':'IT','Director':'Others'
}
people_des={}
for i,x in enumerate(people):
people_des[x]={}
for y in Title[i]:
if title_des[y] not in people_des[x]:
people_des[x][title_des[y]]=[y]
else:
people_des[x][title_des[y]].append(y)
print(people_des)
output:
{'Tim': {'IT': ['DevOps'], 'Others': ['Director']}, 'john': {'Executive': ['CEO', 'COO', 'CTO']}, 'Mary': {'Executive': ['COO', 'MD']}}
Start by arranging your input data in a dictionary-of-lists form:
>>> name_to_titles = {
'John D': ['CEO', 'COO', 'CTO'],
'Mary J': ['COO', 'MD'],
'Tim C': ['Dev Ops', 'Director']
}
Then loop over the input dictionary to create the reverse mapping:
>>> title_to_names = {}
>>> for name, titles in name_to_titles.items():
for title in titles:
title_to_names.setdefault(title, []).append(name)
>>> import pprint
>>> pprint.pprint(title_to_names)
{'CEO': ['John D'],
'COO': ['John D', 'Mary J'],
'CTO': ['John D'],
'Dev Ops': ['Tim C'],
'Director': ['Tim C'],
'MD': ['Mary J']}
I propose this if you mean you have the string:
s = '''Name Title
--------------------
John D CEO, COO, CTO
Mary J COO, MD
Tim C Dev Ops, Director
Title Executive IT Other
-----------------------------
CEO 1
COO 1
CTO 1
MD 1
Dev Ops 1
Director 1
'''
lines = s.split('\n')
it = iter(lines)
for line in it:
if line.startswith('Name'):
break
next(it) # '--------------------'
for line in it:
if not line:
break
split = line.split()
titles = split[2:]
name = split[:2]
print ' '.join(name), titles
# John D ['CEO,', 'COO,', 'CTO']
# Mary J ['COO,', 'MD']
# Tim C ['Dev', 'Ops,', 'Director']