Populate a multidimensional array (recursive relationship) from query - asp.net

I'm trying to populate a multidimensional array that would support the following recursive relationship (the DATA is coming from a database table).
This multidimensional array would be used to generate the list below. I have minimal experience with multidimensional arrays in VB.NET. Any help would be greatly appreciated. If you think there's a better way to achieve this, let me know.
DATA
ID NAME PARENTID
10 Bobby Brown 50
20 Dave Matthew 80
30 Sergey Boostad 50
40 Linda View 50
50 Bill Lumberg
60 Rina Gina 50
70 Ben Thompson 100
80 Maria Tree 50
90 Gustav Duffield 80
100 Jon Theodore
110 Cedric Loomis 100
120 Jeremy Oscar 100
OUTPUT (to achieve)
[50] - Bill Lumberg
[10] - Bobby Brown
[30] - Sergey Boostad
[40] - Linda View
[60] - Rina Gina
[80] - Maria Tree
[20] - Dave Matthew
[90] - Gustav Duffield
[100] - Jon Theodore
[70] - Ben Thompson
[110] - Cedric Loomis
[120] - Jeremy Oscar

To store a tree in memory, you can create a class like this:
Public Class NameNode
Public Sub New(name As String)
Me.Name = name
End Sub
Public Property Name As String
Public Level As Integer
Public Property Children As New List(Of NameNode)
End Class
Then, you can use it like this:
Dim bill As New NameNode("Bill Lumberg")
bill.Children.Add(New NameNode("Bobby Brown")
bill.Children.Add(New NameNode("Sergey Boostad")
To fill it from a flat DataSet, you'd need to make a recursive method, for instance:
Public Function BuildNode(data As DataSet, nameId As Integer, level As Integer), As NameNode
Dim node As New NameNode()
node.Level = level
' Find name with the ID in the dataset and set the node's name property accordingly
Dim childIds As New List(Of Integer)
' Search Get a list of all the name ID's that have the current ID as their parent
For Each i As Integer In childIds
node.Children.Add(BuildNode(data, i, level + 1))
Next
Return node
End Function
Then you could build the whole Bill Lumberg branch by calling it like this:
Dim bill As NameNode = BuildNode(data, 50, 0)

Related

PowerApps - One Collection feeds another, with List lookups

There are a few steps I'm trying to hit, here.
STEP 1:
I have created a Collection (ScanDataCollection) with the following command:
ClearCollect(ScanDataCollection,Split(ScanData.Text,Char(10)));
Where ScanData is a multiline text control, containing data strings such as this:
REQ1805965.RITM2055090.01
REQ1805965.RITM2055091.01
REQ1805982.RITM2055144.01
REQ1805982.RITM2055145.01
This produces a Collection of:
RESULT
REQ1805965.RITM2055090.01
REQ1805965.RITM2055091.01
REQ1805982.RITM2055144.01
REQ1805982.RITM2055145.01
The unique lookup value in this list is the RITM string (for example: RITM2055091)
I want to build a Collection that looks like this:
CUSTOMERNAME CUSTOMEREMAIL MANAGERNAME MANAGEREMAIL ITEMLIST
Edward edward#fish.com Tony tony#fish.com <li><strong>REQ1805965 - RITM2055090 - Vulcan Banana</strong></li>
Edward edward#fish.com Tony tony#fish.com <li><strong>REQ1805965 - RITM2055091 - Vulcan Grape</strong></li>
Joseph joey#fish.com Kate kate#fish.com <li><strong>REQ1805982 - RITM2055144 - Romulan Catfish</strong></li>
Joseph joey#fish.com Kate kate#fish.com <li><strong>REQ1805982 - RITM2055145 - Romulan Salmon</strong></li>
The values in the rows come from a List (called "Spiderfood" at the moment) in SharePoint (this is where RITM value is typically unique, and can be used as the lookup):
Title REQUEST RITM TASK OPENED_DATE ITEM_DESCRIPTION VIP CUSTOMER_NAME CUSTOMER_NT MANAGER_NAME MANAGER_NT TASK_DESCRIPTION CUSTOMER_LOCATION
8-5-2021 REQ1805965 RITM2055090 TASK123 7-27-2021 Vulcan Banana false Edward edward#fish.com Tony tony#fish.com a string a string
8-5-2021 REQ1805965 RITM2055091 TASK123 7-27-2021 Vulcan Grape false Edward edward#fish.com Tony tony#fish.com a string a string
8-5-2021 REQ1805982 RITM2055144 TASK123 7-27-2021 Romulan Catfish false Joseph joey#fish.com Kate kate#fish.com a string a string
8-5-2021 REQ1805982 RITM2055145 TASK123 7-27-2021 Romulan Salmon false Joseph joey#fish.com Kate kate#fish.com a string a string
...[among hundreds of other records in this List]
Then...
STEP 2:
Take the Collection I built above, and deduplicate, based on CUSTOMEREMAIL, but in the process of deduplicating, concatenate the items in the ITEMLIST column.
The result would be a Collection with only two rows, for example:
CUSTOMERNAME CUSTOMEREMAIL MANAGERNAME MANAGEREMAIL ITEMLIST
Edward edward#fish.com Tony tony#fish.com <li><strong>REQ1805965 - RITM2055090 - Vulcan Banana</strong></li><li><strong>REQ1805965 - RITM2055091 - Vulcan Grape</strong></li>
Joseph joey#fish.com Kate kate#fish.com <li><strong>REQ1805982 - RITM2055144 - Romulan Catfish</strong></li><li><strong>REQ1805982 - RITM2055145 - Romulan Salmon</strong></li>
I sure would appreciate guidance/suggestions on this, please!
Thank you kindly in advance!
Okay, for STEP 1:
ClearCollect(ScanDataCollection,Split(ScanData.Text,Char(10)));
ClearCollect(MailingListExploded, AddColumns(ScanDataCollection,
"CustomerName", LookUp('Spiderfood - RITMs', RITM = Mid(Result, 12, 11), Customer_Name),
"CustomerEmail", "edward#fish.com", // this is what I use as a test so that I don't email customers.
//"CustomerEmail", LookUp('Spiderfood - RITMs', RITM = Mid(Result, 12, 11), Customer_NT),
"ManagerName", LookUp('Spiderfood - RITMs', RITM = Mid(Result, 12, 11), Manager_Name),
"ManagerEmail", LookUp('Spiderfood - RITMs', RITM = Mid(Result, 12, 11), Manager_NT),
"ItemListHTML", "<li><strong>" & Left(Result,10) & " - " & Mid(Result, 12, 11) & " - " & LookUp('Spiderfood - RITMs', RITM = Mid(Result, 12, 11), Item_Description) & "</li></strong>"));
It adds an additional column from ScanDataCollection called "Result", but I can live with that. (I take it out later)
I had to add that specific list ('Spiderfood - RITMs') as a resource to the PowerApp project, which took me a minute to remember. Derp.
It offers a delegation warning about the use of Lookup if the dataset is very large (well, it's gonna be around 15,000, give or take), but for now, I'll not worry about it.
Now, on to STEP 2:
What would have helped me quicker on this would be to better understand the GROUPBY function, and how it can have multiple arguments, and concatenating the strings was a bit of a headscratcher.
But it seems to work, so here it is:
// Trim away the Result column
ClearCollect(MailingListExplodedTrimmed, DropColumns(MailingListExploded, "Result"));
// Group and concatenate - TransmissionGrid is what we need to send the emails
ClearCollect(RecordsByCustEmail, GroupBy(MailingListExplodedTrimmed, "CustomerEmail", "CustomerName", "ManagerName", "ManagerEmail", "OrderData"));
ClearCollect(TransmissionGridExtra, AddColumns(RecordsByCustEmail, "ConcatenatedOrderString", Concat(OrderData, ItemListHTML)));
ClearCollect(TransmissionGrid, DropColumns(TransmissionGridExtra, "OrderData"));
Notify("Process complete!");
I might be able to shave away some steps by nesting things, but in this instance I wanted to be super obvious in case I have to look at this in 96 hours.
Anyway, that's what did it for me. Onward!

Data Scraping with list in excel

I have a list in Excel. One code in Column A and another in Column B.
There is a website in which I need to input both the details in two different boxes and it takes to another page.
That page contains certain details which I need to scrape in Excel.
Any help in this?
Ok. Give this a shot:
import pandas as pd
import requests
df = pd.read_excel('C:/test/data.xlsx')
url = 'http://rla.dgft.gov.in:8100/dgft/IecPrint'
results = pd.DataFrame()
for row in df.itertuples():
payload = {
'iec': '%010d' %row[1],
'name':row[2]}
response = requests.post(url, params=payload)
print ('IEC: %010d\tName: %s' %(row[1],row[2]))
try:
dfs = pd.read_html(response.text)
except:
print ('The name Given By you does not match with the data OR you have entered less than three letters')
temp_df = pd.DataFrame([['%010d' %row[1],row[2], 'ERROR']],
columns = ['IEC','Party Name and Address','ERROR'])
results = results.append(temp_df, sort=False).reset_index(drop=True)
continue
generalData = dfs[0]
generalData = generalData.iloc[:,[0,-1]].set_index(generalData.columns[0]).T.reset_index(drop=True)
directorData = dfs[1]
directorData = directorData.iloc[:,[-1]].T.reset_index(drop=True)
directorData.columns = [ 'director_%02d' %(each+1) for each in directorData.columns ]
try:
branchData = dfs[2]
branchData = branchData.iloc[:,[-1]].T.reset_index(drop=True)
branchData.columns = [ 'branch_%02d' %(each+1) for each in branchData.columns ]
except:
branchData = pd.DataFrame()
print ('No Branch Data.')
temp_df = pd.concat([generalData, directorData, branchData], axis=1)
results = results.append(temp_df, sort=False).reset_index(drop=True)
results.to_excel('path.new_file.xlsx', index=False)
Output:
print (results.to_string())
IEC IEC Allotment Date File Number File Date Party Name and Address Phone No e_mail Exporter Type IEC Status Date of Establishment BIN (PAN+Extension) PAN ISSUE DATE PAN ISSUED BY Nature Of Concern Banker Detail director_01 director_02 director_03 branch_01 branch_02 branch_03 branch_04 branch_05 branch_06 branch_07 branch_08 branch_09
0 0305008111 03.05.2005 04/04/131/51473/AM20/ 20.08.2019 NISSAN MOTOR INDIA PVT. LTD. PLOT-1A,SIPCOT IN... 918939917907 shailesh.kumar#rnaipl.com 5 Merchant/Manufacturer Valid IEC 2005-02-07 AACCN0695D FT001 NaN NaN 3 Private Limited STANDARD CHARTERED BANK A/C Type:1 CA A/C No :... HARDEEP SINGH BRAR GURMEL SINGH BRAR HOUSE NO ... JEROME YVES MARIE SAIGOT THIERRY SAIGOT A9/2, ... KOJI KAWAKITA KIHACHI KAWAKITA 3-21-3, NAGATAK... Branch Code:165TH FLOOR ORCHID BUSINESS PARK,S... Branch Code:14NRPDC , WAREHOUSE NO.B -2A,PATAU... Branch Code:12EQUINOX BUSINESS PARK TOWER 3 4T... Branch Code:8GRAND PALLADIUM,5TH FLR.,B WING,,... Branch Code:6TVS LOGISTICS SERVICES LTD.SING,C... Branch Code:2PLOT 1A SIPCOT INDUL PARK,ORAGADA... Branch Code:5BLDG.NO.3 PART,124A,VALLAM A,SRIP... Branch Code:15SURVEY NO. 678 679 680 681 682 6... Branch Code:10INDOSPACE SKCL INDL.PARK,BULD.NO...

How to reverse the Lastname,Firstname of an expression inside a Cognos data item?

I created a list report in Cognos and the LAST NAME column is currently in Lastname,Firstname order, with no spaces except for Firstname with a second name included.
From this current set-up
LAST_NAME COLUMN
Morello,Mortel
Chopra,Deepak
Fothergill,Mike Edward
Smith,David
I'm hoping to get this result.
NEW DATA ITEM
Mortel Morello
Deepak Chopra
Mike Edward Fothergill
David Smith
I tried using a substring function but it does not work.
substring(LAST_NAME, position(',', LAST_NAME)+1,
inStr(LAST_NAME, ' ',position(',', LAST_NAME)+1, 1))
This should work:
substring([Last Name],position(',',[Last Name])+1)
+ ' ' +
substring([Last Name],1,position(',',[Last Name])-1)

How can I access the data in a Cassandra Table using RCassandra

I need to get the data in a column of a table Cassandra Database. I am using RCassandra for this. After getting the data I need to do some text mining on it. Please suggest me how do connect to cassandra, and get the data into my R Script using RCassandra
My RScript :
library(RCassandra)
connect.handle <- RC.connect(host="127.0.0.1", port=9160)
RC.cluster.name(connect.handle)
RC.use(connect.handle, 'mykeyspace')
sourcetable <- RC.read.table(connect.handle, "sourcetable")
print(ncol(sourcetable))
print(nrow(sourcetable))
print(sourcetable)
This will print the output as:
> print(ncol(sourcetable))
[1] 1
> print(nrow(sourcetable))
[1] 18
> print(sourcetable)
144 BBC News
158 IBN Live
123 Reuters
131 IBN Live
But my cassandra table contains four columns, but here its showing only 1 column. I need to get each column values separated. So how do I get the individual column values(Eg.each feedurl) What changes should I make in my R script?
My cassandra table, named sourcetable
I have used Cassandra and R with the correct Cran Jar files, but RCassandra is easier. RCassandra is a direct interface to Cassandra without the use of Java. To connect to Cassandra you will use RC.connect to return a connection handle like this.
RC.connect(host = <xxx>, port = <xxx>)
RC.login(conn, username = "bar", password = "foo")
You can then use a RC.get command to retrieve data or RC.ReadTable command to read table data.
BUT, First you should read THIS
I am confused as well. Table demo.emp has 4 row and 4 columns ( empid, deptid, first_name and last_name). Neither RC.get nor RC.read.table gets the all the data.
cqlsh:demo> select * from emp;
empid | deptid | first_name | last_name
-------+--------+------------+-----------
1 | 1 | John | Doe
1 | 2 | Mia | Lewis
2 | 1 | Jean | Doe
2 | 2 | Manny | Lewis
> RC.get.range.slices(c, "emp", limit=10)
[[1]]
key value ts
1 1.474796e+15
2 John 1.474796e+15
3 Doe 1.474796e+15
4 1.474796e+15
5 Mia 1.474796e+15
[[2]]
key value ts
1 1.474796e+15
2 Jean 1.474796e+15
3 Doe 1.474796e+15
4 1.474796e+15
5 Manny 1.474796e+15

parsing text file in tcl and creating dictionary of key value pair where values are in list format

How to seperate following text file and Keep only require data for corresponding :
for example text file have Format:
Name Roll_number Subject Experiment_name Marks Result
Joy 23 Science Exp related to magnet 45 pass
Adi 12 Science Exp electronics 48 pass
kumar 18 Maths prime numbers 49 pass
Piya 19 Maths number roots 47 pass
Ron 28 Maths decimal numbers 12 fail
after parsing above Information and storing in dictionary where key is subject(unique) and values corresponding to subject is list of pass Student name
set studentInfo [dict create]; # Creating empty dictionary
set fp [open input.txt r]
set line_no 0
while {[gets $fp line]!=-1} {
incr line_no
# Skipping line number 1 alone, as it has the column headers
# You can alter this logic, if you want to
if {$line_no==1} {
continue
}
if {[regexp {(\S+)\s+\S+\s+(\S+).*\s(\S+)} $line match name subject result]} {
if {$result eq "pass"} {
# Appending the student's name with key value as 'subject'
dict lappend studentInfo $subject $name
}
}
}
close $fp
puts [dict get $studentInfo]
Output :
Science {Joy Adi} Maths {kumar Piya}

Resources