Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ending flow at two different points #92

Open
david-reiss opened this issue Jan 21, 2020 · 5 comments
Open

ending flow at two different points #92

david-reiss opened this issue Jan 21, 2020 · 5 comments

Comments

@david-reiss
Copy link

I have two places where I want the flow to end, one is after 'BF' at the first waypoint, the second is after 'BR1F' at the second waypoint. This code will only get them both to end at the second waypoint.

(The reason I am using a dict for my partition is so that I can remove the 'None' and then sort the list).

I thought since None doesn't appear in the partitions that it wouldn't appear in the second waypoint, but it seems that every flow must continue to every waypoint.

To summarize, I'd like to end a flow at each waypoint and I don't know how to do that.

Also, I don't know how to make more than 2 'process groups'. Is it possible to have bundles that go from col1 to col2 and from col2 to col3? My process groups seem to have to have column names that are 'source' and 'target' so I'm not sure how to get a third one. If I could, perhaps I could just make these process groups with bundles and not have to use waypoints at all.

Thanks for the help.

df = pd.DataFrame(columns=['source', 'target', '2nd','3rd','4th', '5th', '6th', 'value'])
df['source']=['X','X','X','B','B','B', 'B']
df['3rd'] = ['XBR1', 'XX T B', 'XX T X', 'BR1F', 'BR2C', 'BR2C',None ]#'BR2C']
df['2nd'] = ['XB','XX','XX','BR1','BR2', 'BR2','BF']
df['target'] = ['XBR1C', 'XX T BC', 'XX T XB1',None , 'BR2C R', 'BR2C R', None]
df['value']=[1,1,1,1,1, 1, 1]

pdict = {}
pdict[1] = ['B', 'X']
pdict[2] = sorted(list(set(df['2nd'])))
pdict3list = list(set(df['3rd']))
pdict3list.remove(None)
pdict[3] = sorted(pdict3list)
pdict4list = list(set(df['target']))
pdict4list.remove(None)
pdict[4] = sorted(pdict4list)

nodes = {
'move1': ProcessGroup(pdict[1]),
'move4': ProcessGroup(pdict[4]),
}

part1 = Partition.Simple('process', ['B','X'])
part4 = Partition.Simple('process', pdict[4])
part3 = Partition.Simple('3rd', pdict[3])
part2 = Partition.Simple('2nd', pdict[2])

nodes['move1'].partition = part1
nodes['move4'].partition = part4
nodes['waypoint1'] = Waypoint(part2)
nodes['waypoint2'] = Waypoint(part3)

ordering = [
['move1'],
['waypoint1'],
['waypoint2'],
['move4']
]

bundles = [
Bundle('move1', 'move4', waypoints=['waypoint1', 'waypoint2']),
Bundle('move1', Elsewhere, waypoints=['waypoint1', 'waypoint2']),
]

Update the SDD with the new nodes, ordering & bundles.

sdd = SankeyDefinition(nodes, bundles, ordering, flow_partition=part3)
size = dict(width=600, height=600)
weave(sdd, df).to_widget(**size)

@ricklupton
Copy link
Owner

Hi David, the quick answer is that no, flows only end at ProcessGroups, not Waypoints -- by definition a Waypoint is in the middle of a flow/bundle.

Maybe if you can give a sketch of what you want it to look like I can help?

@david-reiss
Copy link
Author

david-reiss commented Jan 23, 2020 via email

@david-reiss
Copy link
Author

david-reiss commented Jan 23, 2020 via email

@david-reiss
Copy link
Author

david-reiss commented Jan 23, 2020 via email

@ricklupton
Copy link
Owner

With the data setup the way you have it in your example it is possible -- but better to change the data as I show below if possible.

You can get what I think you want by adding two Bundles like this:

bundles = [
Bundle('move1', 'move4', waypoints=['waypoint1', 'waypoint2']),
Bundle('move1', Elsewhere, waypoints=['waypoint1'], flow_selection='x3rd != x3rd'),
Bundle('move1', Elsewhere, waypoints=['waypoint1', 'waypoint2'], flow_selection='x3rd == x3rd'),
]

(note I added an x to the start of the column names, because column names starting with numbers don't work in every situation).

The difficulty is that in your original code, all the flows with target == None where being picked up by the same Bundle, which sent them through both waypoint1 and waypoint2. To get one of them to stop sooner, it has to be in a Bundle that goes through only waypoint1. This solution isn't very intuitive; it works in this case because None is converted to NaN and NaN != NaN, so it picks out the correct flow in each Bundle.

Really, the solution would be to set the target to something meaningful. For example:

df = pd.DataFrame(columns=['source', 'target', 'x2nd','x3rd','x4th', 'x5th', 'x6th', 'value'])
df['source']=['X','X','X','B','B','B', 'B']
df['x3rd'] = ['XBR1', 'XX T B', 'XX T X', 'BR1F', 'BR2C', 'BR2C',None ]#'BR2C']
df['x2nd'] = ['XB','XX','XX','BR1','BR2', 'BR2','BF']
df['target'] = ['XBR1C', 'XX T BC', 'XX T XB1','stop1' , 'BR2C R', 'BR2C R', 'stop2']
df['value']=[1,1,1,1,1, 1, 1]

pdict = {}
pdict[1] = ['B', 'X']
pdict[2] = sorted(list(set(df['x2nd'])))
pdict3list = list(set(df['x3rd']))
pdict3list.remove(None)
pdict[3] = sorted(pdict3list)
pdict[4] = ['BR2C R', 'XBR1C', 'XX T BC', 'XX T XB1']

part1 = Partition.Simple('process', ['B','X'])
part4 = Partition.Simple('process', pdict[4])
part3 = Partition.Simple('x3rd', pdict[3])
part2 = Partition.Simple('x2nd', pdict[2])

nodes = {
    'move1': ProcessGroup(pdict[1], partition = part1),
    'move4': ProcessGroup(pdict[4], partition = part4),
    'stop1': ProcessGroup(['stop1']),
    'stop2': ProcessGroup(['stop2']),
    'waypoint1': Waypoint(part2),
    'waypoint2': Waypoint(part3)
}

ordering = [
    [[], ['move1']],
    [['stop1'], ['waypoint1']],
    [['stop2'], ['waypoint2']],
    [[], ['move4']],
]

bundles = [
Bundle('move1', 'move4', waypoints=['waypoint1', 'waypoint2']),
Bundle('move1', 'stop1', waypoints=[]),
Bundle('move1', 'stop2', waypoints=['waypoint1']),
]

sdd = SankeyDefinition(nodes, bundles, ordering, flow_partition=part3)
size = dict(width=600, height=600)
weave(sdd, df).to_widget(debugging=True, **size)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants