In [1]:
import pandas as pd

coverage = pd.read_csv("../dataset/jacoco.csv")[['PACKAGE', 'CLASS', 'LINE_COVERED', 'LINE_MISSED']]
coverage.head()


Out[1]:
PACKAGE CLASS LINE_COVERED LINE_MISSED
0 org.springframework.samples.petclinic PetclinicInitializer 24 0
1 org.springframework.samples.petclinic.model NamedEntity 4 1
2 org.springframework.samples.petclinic.model Specialty 1 0
3 org.springframework.samples.petclinic.model PetType 1 0
4 org.springframework.samples.petclinic.model Vets 0 4

In [2]:
coverage['lines'] = coverage.LINE_COVERED + coverage.LINE_MISSED
coverage['ratio'] = coverage.LINE_COVERED / coverage.lines
coverage.head()


Out[2]:
PACKAGE CLASS LINE_COVERED LINE_MISSED lines ratio
0 org.springframework.samples.petclinic PetclinicInitializer 24 0 24 1.0
1 org.springframework.samples.petclinic.model NamedEntity 4 1 5 0.8
2 org.springframework.samples.petclinic.model Specialty 1 0 1 1.0
3 org.springframework.samples.petclinic.model PetType 1 0 1 1.0
4 org.springframework.samples.petclinic.model Vets 0 4 4 0.0

In [3]:
%matplotlib inline

coverage.groupby("PACKAGE").mean()['ratio'].plot(kind='barh')


Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x272b6f489e8>

In [4]:
import py2neo

graph = py2neo.Graph()

query="""
MATCH (t:Type)
RETURN t.fqn LIMIT 10
"""

pd.DataFrame(graph.data(query))


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
C:\dev\apps\Anaconda3\lib\site-packages\py2neo\database\__init__.py in __new__(cls, *uris, **settings)
    317         try:
--> 318             inst = cls.__instances[key]
    319         except KeyError:

KeyError: (<class 'py2neo.database.Graph'>, <ServerAddress settings={}>, 'data')

During handling of the above exception, another exception occurred:

ConnectionRefusedError                    Traceback (most recent call last)
C:\dev\apps\Anaconda3\lib\site-packages\py2neo\packages\httpstream\http.py in submit(method, uri, body, headers)
    321         try:
--> 322             response = send()
    323         except BadStatusLine as err:

C:\dev\apps\Anaconda3\lib\site-packages\py2neo\packages\httpstream\http.py in send(reconnect)
    316             log.debug("> %s: %s", key, value)
--> 317         http.request(xstr(method), xstr(uri.absolute_path_reference), body, headers)
    318         return http.getresponse(**getresponse_args)

C:\dev\apps\Anaconda3\lib\http\client.py in request(self, method, url, body, headers, encode_chunked)
   1238         """Send a complete request to the server."""
-> 1239         self._send_request(method, url, body, headers, encode_chunked)
   1240 

C:\dev\apps\Anaconda3\lib\http\client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1284             body = _encode(body, 'body')
-> 1285         self.endheaders(body, encode_chunked=encode_chunked)
   1286 

C:\dev\apps\Anaconda3\lib\http\client.py in endheaders(self, message_body, encode_chunked)
   1233             raise CannotSendHeader()
-> 1234         self._send_output(message_body, encode_chunked=encode_chunked)
   1235 

C:\dev\apps\Anaconda3\lib\http\client.py in _send_output(self, message_body, encode_chunked)
   1025         del self._buffer[:]
-> 1026         self.send(msg)
   1027 

C:\dev\apps\Anaconda3\lib\http\client.py in send(self, data)
    963             if self.auto_open:
--> 964                 self.connect()
    965             else:

C:\dev\apps\Anaconda3\lib\site-packages\py2neo\packages\httpstream\http.py in connect(self)
     79                                              socket_timeout,
---> 80                                              self.source_address)
     81         self.sock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)

C:\dev\apps\Anaconda3\lib\socket.py in create_connection(address, timeout, source_address)
    723     if err is not None:
--> 724         raise err
    725     else:

C:\dev\apps\Anaconda3\lib\socket.py in create_connection(address, timeout, source_address)
    712                 sock.bind(source_address)
--> 713             sock.connect(sa)
    714             # Break explicitly a reference cycle

ConnectionRefusedError: [WinError 10061] Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte

During handling of the above exception, another exception occurred:

SocketError                               Traceback (most recent call last)
<ipython-input-4-92b918cded43> in <module>()
      1 import py2neo
      2 
----> 3 graph = py2neo.Graph()
      4 
      5 query="""

C:\dev\apps\Anaconda3\lib\site-packages\py2neo\database\__init__.py in __new__(cls, *uris, **settings)
    325             use_bolt = address.bolt
    326             if use_bolt is None:
--> 327                 use_bolt = version_tuple(inst.__remote__.get().content["neo4j_version"]) >= (3,)
    328             if use_bolt:
    329                 auth = get_auth(address)

C:\dev\apps\Anaconda3\lib\site-packages\py2neo\database\http.py in get(self, headers, redirect_limit, **kwargs)
    152         kwargs.update(cache=True)
    153         try:
--> 154             response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
    155         except (ClientError, ServerError) as error:
    156             if error.status_code == UNAUTHORIZED:

C:\dev\apps\Anaconda3\lib\site-packages\py2neo\packages\httpstream\http.py in get(self, if_modified_since, headers, redirect_limit, **kwargs)
    964             object from which content can be read
    965         """
--> 966         return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs)
    967 
    968     def put(self, body=None, headers=None, **kwargs):

C:\dev\apps\Anaconda3\lib\site-packages\py2neo\packages\httpstream\http.py in __get_or_head(self, method, if_modified_since, headers, redirect_limit, **kwargs)
    941             headers["If-Modified-Since"] = formatdate(datetime_to_timestamp(if_modified_since), usegmt=True)
    942         rq = Request(method, self.uri, None, headers)
--> 943         return rq.submit(redirect_limit=redirect_limit, **kwargs)
    944 
    945     def head(self, if_modified_since=None, headers=None, redirect_limit=5, **kwargs):

C:\dev\apps\Anaconda3\lib\site-packages\py2neo\packages\httpstream\http.py in submit(self, redirect_limit, **response_kwargs)
    431         uri = self.uri
    432         while True:
--> 433             http, rs = submit(self.method, uri, self.body, self.headers)
    434             status_class = rs.status // 100
    435             if status_class == 3:

C:\dev\apps\Anaconda3\lib\site-packages\py2neo\packages\httpstream\http.py in submit(method, uri, body, headers)
    360                                       host_port=uri.host_port)
    361         else:
--> 362             raise SocketError(code, description, host_port=uri.host_port)
    363     else:
    364         return http, response

SocketError: Unknown error

In [5]:
coverage['fqn'] = coverage.PACKAGE + "." + coverage.CLASS
coverage[['fqn', 'ratio']].head()


Out[5]:
fqn ratio
0 org.springframework.samples.petclinic.Petclini... 1.0
1 org.springframework.samples.petclinic.model.Na... 0.8
2 org.springframework.samples.petclinic.model.Sp... 1.0
3 org.springframework.samples.petclinic.model.Pe... 1.0
4 org.springframework.samples.petclinic.model.Vets 0.0

Laden der Coverage-Informationen in die Graphdatenbank


In [6]:
query="""
    UNWIND {coverage_data} as coverage
    MATCH (t:Type {fqn : coverage.fqn})
    MERGE (t)-[:HAS_MEASURE]->(m)
    SET 
        m:Measure:Coverage, 
        m.ratio = coverage.ratio
    RETURN t.fqn as fqn, m.ratio as ratio
"""

result = graph.run(query, coverage_data=coverage.to_dict(orient='records')).data()
pd.DataFrame(result).head()


Out[6]:
fqn ratio
0 org.springframework.samples.petclinic.Petclini... 1.0
1 org.springframework.samples.petclinic.model.Na... 0.8
2 org.springframework.samples.petclinic.model.Sp... 1.0
3 org.springframework.samples.petclinic.model.Pe... 1.0
4 org.springframework.samples.petclinic.model.Vets 0.0

In [7]:
query = """
MATCH 
  (t:Type)-[:BELONGS_TO]->(s:Subdomain),
  (t)-[:HAS_CHANGE]->(ch:Change),
  (t)-[:HAS_MEASURE]->(co:Coverage)
OPTIONAL MATCH
  (t)-[:HAS_BUG]->(b:BugInstance)   
RETURN 
  s.name as ASubdomain,
  COUNT(DISTINCT t) as Types,
  COUNT(DISTINCT ch) as Changes,
  AVG(co.ratio) as Coverage,
  COUNT(DISTINCT b) as Bugs
ORDER BY Coverage ASC, Bugs DESC
"""
pd.DataFrame(graph.data(query))


Out[7]:
ASubdomain Bugs Changes Coverage Types
0 Vet 0 75 0.170000 5
1 Visit 0 90 0.368056 6
2 Pet 1 165 0.488737 11
3 Owner 3 94 0.506932 4
4 crossfunctional 2 53 0.589231 5
5 Clinic 0 26 0.888889 1
6 Person 0 5 1.000000 1
7 Specialty 0 4 1.000000 1

In [8]:
query = """
MATCH 
  (t:Type)-[:IS_A]->(ta:TechnicalAspect),
  (t)-[:HAS_CHANGE]->(ch:Change),
  (t)-[:HAS_MEASURE]->(co:Coverage)
OPTIONAL MATCH
  (t)-[:HAS_BUG]->(b:BugInstance)   
RETURN 
  ta.name as ATechnicalAspect,
  COUNT(DISTINCT t) as Types,
  COUNT(DISTINCT ch) as Changes,
  AVG(co.ratio) as Coverage,
  COUNT(DISTINCT b) as Bugs
ORDER BY Coverage ASC, Bugs DESC
"""
pd.DataFrame(graph.data(query))


Out[8]:
ATechnicalAspect Bugs Changes Coverage Types
0 jdbc 1 152 0.000000 8
1 util 2 23 0.371429 2
2 web 2 154 0.618818 7
3 jpa 0 54 0.702501 4
4 model 1 91 0.731240 10
5 service 0 26 0.888889 1
6 petclinic 0 5 1.000000 1

In [ ]: