In [105]:
import pandas as pd
main_devs = pd.read_csv(r'C:\dev\repos\spring-petclinic\main_dev.csv')
main_devs.head()


Out[105]:
entity main-dev added total-added ownership
0 .bowerrc IHABRITANE 3 4 0.75
1 .classpath Costin Leau 43 81 0.53
2 .editorconfig Antoine Rey 14 14 1.00
3 .gitignore Mic 6 11 0.55
4 .mvn/wrapper/maven-wrapper.jar patrickcrocker 0 0 0.00

In [106]:
initial_number_of_columns = len(main_devs.columns)
initial_number_of_columns


Out[106]:
5

In [108]:
main_devs = main_devs.join(main_devs['entity'].str.split("/", expand=True))
main_devs.head()


Out[108]:
entity main-dev added total-added ownership 0 1 2 3 4 5 6 7 8 9 10
0 .bowerrc IHABRITANE 3 4 0.75 .bowerrc None None None None None None None None None None
1 .classpath Costin Leau 43 81 0.53 .classpath None None None None None None None None None None
2 .editorconfig Antoine Rey 14 14 1.00 .editorconfig None None None None None None None None None None
3 .gitignore Mic 6 11 0.55 .gitignore None None None None None None None None None None
4 .mvn/wrapper/maven-wrapper.jar patrickcrocker 0 0 0.00 .mvn wrapper maven-wrapper.jar None None None None None None None None

In [109]:
columns_to_group = list(range(0, len(main_devs.columns)-initial_number_of_columns))
columns_to_group


Out[109]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

In [121]:
hierarchical_main_devs = main_devs.fillna("").groupby(columns_to_group).first()
hierarchical_main_devs.head()


Out[121]:
entity main-dev added total-added ownership
0 1 2 3 4 5 6 7 8 9 10
.bowerrc .bowerrc IHABRITANE 3 4 0.75
.classpath .classpath Costin Leau 43 81 0.53
.editorconfig .editorconfig Antoine Rey 14 14 1.00
.gitignore .gitignore Mic 6 11 0.55
.mvn wrapper maven-wrapper.jar .mvn/wrapper/maven-wrapper.jar patrickcrocker 0 0 0.00

In [122]:
hierarchical_main_devs = hierarchical_main_devs.replace("", pd.np.nan)
hierarchical_main_devs


Out[122]:
entity main-dev added total-added ownership
0 1 2 3 4 5 6 7 8 9 10
.bowerrc .bowerrc IHABRITANE 3 4 0.75
.classpath .classpath Costin Leau 43 81 0.53
.editorconfig .editorconfig Antoine Rey 14 14 1.00
.gitignore .gitignore Mic 6 11 0.55
.mvn wrapper maven-wrapper.jar .mvn/wrapper/maven-wrapper.jar patrickcrocker 0 0 0.00
maven-wrapper.properties .mvn/wrapper/maven-wrapper.properties patrickcrocker 1 1 1.00
.project .project Costin Leau 36 59 0.61
.settings .jsdtscope .settings/.jsdtscope Keith Donald 11 13 0.85
com.springsource.server.ide.jdt.core.xml .settings/com.springsource.server.ide.jdt.core... Keith Donald 2 2 1.00
org.eclipse.jdt.core.prefs .settings/org.eclipse.jdt.core.prefs Keith Donald 12 16 0.75
org.eclipse.jst.common.project.facet.core.prefs .settings/org.eclipse.jst.common.project.facet... Keith Donald 3 3 1.00
org.eclipse.m2e.core.prefs .settings/org.eclipse.m2e.core.prefs Mic 4 4 1.00
org.eclipse.m2e.wtp.prefs .settings/org.eclipse.m2e.wtp.prefs Mic 2 2 1.00
org.eclipse.wst.common.component .settings/org.eclipse.wst.common.component Keith Donald 20 38 0.53
org.eclipse.wst.common.project.facet.core.xml .settings/org.eclipse.wst.common.project.facet... Keith Donald 7 11 0.64
org.eclipse.wst.jsdt.ui.superType.container .settings/org.eclipse.wst.jsdt.ui.superType.co... Keith Donald 1 1 1.00
org.eclipse.wst.jsdt.ui.superType.name .settings/org.eclipse.wst.jsdt.ui.superType.name Keith Donald 1 1 1.00
org.eclipse.wst.validation.prefs .settings/org.eclipse.wst.validation.prefs Keith Donald 6 6 1.00
org.maven.ide.eclipse.prefs .settings/org.maven.ide.eclipse.prefs Keith Donald 9 9 1.00
org.springframework.ide.eclipse.beans.core.prefs .settings/org.springframework.ide.eclipse.bean... Keith Donald 3 3 1.00
org.springframework.ide.eclipse.core.prefs .settings/org.springframework.ide.eclipse.core... Keith Donald 67 80 0.84
.springBeans .springBeans Mic 47 61 0.77
.travis.yml .travis.yml Antoine Rey 0 0 0.00
README.md README.md michaelisvy 4 4 1.00
authors.txt authors.txt Mic 25 25 1.00
bower.json bower.json IHABRITANE 11 13 0.85
db build.xml db/build.xml Costin Leau 85 85 1.00
dropTables.txt db/dropTables.txt Costin Leau 7 7 1.00
emptyDB.txt db/emptyDB.txt Costin Leau 7 7 1.00
mysql createDB.txt db/mysql/createDB.txt Costin Leau 3 3 1.00
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
src test java org springframework samples petclinic { => repository} jpa JpaVisitRepositoryImplTests.java src/test/java/org/springframework/samples/petc... Mic 2 2 1.00
springdatajpa JpaOwnerRepositoryImplTests.java src/test/java/org/springframework/samples/petc... Mic 2 2 1.00
JpaPetRepositoryImplTests.java src/test/java/org/springframework/samples/petc... Mic 2 2 1.00
JpaVetRepositoryImplTests.java src/test/java/org/springframework/samples/petc... Mic 2 2 1.00
JpaVisitRepositoryImplTests.java src/test/java/org/springframework/samples/petc... Mic 2 2 1.00
SpringDataOwnerRepositoryTests.java src/test/java/org/springframework/samples/petc... Mic 2 2 1.00
{AbstractClinicTests.java => AbstractPetRepositoryTests.java} src/test/java/org/springframework/samples/petc... Mic 24 24 1.00
{jpa EntityManagerClinicTests.java => aspects UsageLogAspectTests.java} src/test/java/org/springframework/samples/petc... Mic 4 4 1.00
{jpa => springdatajpa} SpringDataOwnerRepositoryTests.java src/test/java/org/springframework/samples/petc... Mic 1 1 1.00
{repository AbstractOwnerRepositoryTests.java => service AbstractClinicServiceTests.java} src/test/java/org/springframework/samples/petc... Mic 91 91 1.00
jdbc JdbcOwnerRepositoryImplTests.java => service ClinicServiceJdbcTests.java} src/test/java/org/springframework/samples/petc... Mic 2 2 1.00
jpa JpaOwnerRepositoryImplTests.java => service ClinicServiceJpaTests.java} src/test/java/org/springframework/samples/petc... Mic 2 2 1.00
springdatajpa SpringDataOwnerRepositoryTests.java => service ClinicServiceSpringDataJpaTests.java} src/test/java/org/springframework/samples/petc... Mic 2 2 1.00
jmeter petclinic_test_plan.jmx src/test/jmeter/petclinic_test_plan.jmx Antoine Rey 435 436 1.00
resources log4j.xml src/test/resources/log4j.xml Costin Leau 28 28 1.00
logback-test.xml src/test/resources/logback-test.xml Gordon Dickens 24 24 1.00
org springframework samples petclinic AbstractClinicTests-context.xml src/test/resources/org/springframework/samples... Keith Donald 24 52 0.46
hibernate HibernateClinicTests-context.xml src/test/resources/org/springframework/samples... Costin Leau 32 35 0.91
jdbc JdbcClinicTests-context.xml src/test/resources/org/springframework/samples... Mic 30 30 1.00
SimpleJdbcClinicTests-context.xml src/test/resources/org/springframework/samples... Costin Leau 11 11 1.00
jpa applicationContext-entityManager.xml src/test/resources/org/springframework/samples... Costin Leau 16 17 0.94
applicationContext-hibernateAdapter.xml src/test/resources/org/springframework/samples... Costin Leau 9 9 1.00
applicationContext-jpaCommon.xml src/test/resources/org/springframework/samples... Costin Leau 31 62 0.50
applicationContext-openJpaAdapter.xml src/test/resources/org/springframework/samples... Costin Leau 9 9 1.00
applicationContext-toplinkAdapter.xml src/test/resources/org/springframework/samples... Costin Leau 9 9 1.00
travis.yml travis.yml michaelisvy 3 3 1.00
travis.yml => .travis.yml travis.yml => .travis.yml michaelisvy 0 0 0.00
{org.springframework.samples.petclinic src main webapp => src main webapp resources} images banner-graphic.png {org.springframework.samples.petclinic/src/mai... Mic 0 0 0.00
pets.png {org.springframework.samples.petclinic/src/mai... Mic 0 0 0.00
springsource-logo.png {org.springframework.samples.petclinic/src/mai... Mic 0 0 0.00

1710 rows × 5 columns


In [114]:
import pandas as pd
import json


# order in the groupby here matters, it determines the json nesting
# the groupby call makes a pandas series by grouping 'the_parent' and 'the_child', while summing the numerical column 'child_size'
df1 = hierarchical_main_devs



# start a new flare.json document
flare = dict()
flare = {"name":"flare", "children": []}

d =dict()
d ['children'] = []

for line in df1.values:
    
    the_parent = line[0]
    the_child = line[1]
    child_size = line[2]

    # make a list of keys
    keys_list = []
    for item in d['children']:
        keys_list.append(item['name'])

    # if 'the_parent' is NOT a key in the flare.json yet, append it
    if not the_parent in keys_list:
        d['children'].append({"name":the_parent, "children":[{"name":the_child, "size":child_size}]})

    # if 'the_parent' IS a key in the flare.json, add a new child to it
    else:
        d['children'][keys_list.index(the_parent)]['children'].append({"name":the_child, "size":child_size})

flare = d


# export the final result to a json file
with open('data/flare.json', 'w') as outfile:
    json.dump(flare, outfile)

In [94]:
hierarchical_main_devs.reset_index().to_json("data/main_devs_split.json", orient='split')
hierarchical_main_devs.reset_index().to_json("data/main_devs_records.json", orient='records')
hierarchical_main_devs.reset_index().to_json("data/main_devs_index.json", orient='index')
hierarchical_main_devs.reset_index().to_json("data/main_devs_columns.json", orient='columns')
hierarchical_main_devs.reset_index().to_json("data/main_devs_values.json", orient='values')