コード例 #1
0
ファイル: tests.py プロジェクト: bingxindu/circlify
 def test_circlify(self):
     """Check the coordinates of the circles returned are expected."""
     actual = circ.circlify(self.data, show_enclosure=True)
     expected = [
         circ.Circle(x=0.0, y=0.0, r=1.0, level=0),
         circ.Circle(x=0.09222041925800777, y=0.8617116738294696,
                     r=0.09068624109026069),
         circ.Circle(x=-0.40283175658099674, y=0.7512387781681531,
                     r=0.12824971207048294),
         circ.Circle(x=0.3252787490004198, y=0.7776370388468007,
                     r=0.15707317711577193),
         circ.Circle(x=0.48296614887228806, y=0.4541723195782383,
                     r=0.20278059970175755),
         circ.Circle(x=-0.6132109517981927, y=0.4490810687795324,
                     r=0.23993324126007678),
         circ.Circle(x=-0.045884607890591435, y=-0.6977206243364218,
                     r=0.3007722353441051),
         circ.Circle(x=-0.04661299415374866, y=0.4678014425767657,
                     r=0.32697389223002427),
         circ.Circle(x=-0.411432317820337, y=-0.13064957525245907,
                     r=0.3739089508053733),
         circ.Circle(x=0.35776879346704843, y=-0.13064957525245907,
                     r=0.39529216048201216),
     ]
     self.display(actual, reversed(self.data + [None]))
     self.assertEqual(expected, actual)
コード例 #2
0
 def test_handle_dict_w_children(self):
     actual = circ.circlify([self.data[2]])
     expected = [
         circ.Circle(
             level=1,
             ex={
                 "id": "a0",
                 "datum": 0.8,
                 "children": [0.3, 0.2, 0.2, 0.1]
             },
         ),
         circ.Circle(
             level=2,
             ex={"datum": 0.1},
         ),
         circ.Circle(
             level=2,
             ex={"datum": 0.2},
         ),
         circ.Circle(
             level=2,
             ex={"datum": 0.2},
         ),
         circ.Circle(
             level=2,
             ex={"datum": 0.3},
         ),
     ]
     actual_level_and_ex = ignore_xyr(actual)
     self.assertEqual(expected, actual_level_and_ex)
コード例 #3
0
 def test_two_equal_values(self):
     """Two equal circle cases is also trivial."""
     actual = circ.circlify([1.0, 1.0])
     expected = [
         circ.Circle(x=0.5, r=0.5, ex={"datum": 1.0}),
         circ.Circle(x=-0.5, r=0.5, ex={"datum": 1.0}),
     ]
     self.assertEqual(actual, expected)
コード例 #4
0
ファイル: tests.py プロジェクト: bingxindu/circlify
 def test_handle_dict_w_children(self):
     actual = circ.circlify([self.data[2]])
     expected = [
         circ.Circle(ex={'id': 'a0', 'datum': 0.8,
                         'children': [0.3, 0.2, 0.2, 0.1]}),
         circ.Circle(x=0.548583479265826, y=0.4560515085667499,
                     r=0.28660893460220066, level=2),
         circ.Circle(x=-0.5063467568453794, y=-0.31184906572942,
                     r=0.40532624241173565, level=2),
         circ.Circle(x=-0.14196677995553317, y=0.41229503843233234,
                     r=0.40532624241173565, level=2),
         circ.Circle(x=0.3954007222005534, y=-0.31184906572942,
                     r=0.4964212366341972, level=2)
     ]
     self.assertEqual(expected, actual)
コード例 #5
0
 def test_dict_w_datum_and_id(self):
     """Handles dict with data and an id"""
     actual = circ._handle([{"datum": 1, "id": "42"}], 1)
     self.assertEqual([circ.Circle(r=1, ex={
         "id": "42",
         "datum": 1
     })], actual)
コード例 #6
0
def ignore_xyr(circles):
    """Change all x and y to 0.0 and r to 1.0

    This is useful for those tests whose actual (x, y, r) data can change.

    """
    return [circ.Circle(level=c.level, ex=c.ex) for c in circles]
コード例 #7
0
ファイル: tests.py プロジェクト: bingxindu/circlify
 def test_handle_children(self):
     """A dict that has children."""
     actual = circ._handle([{'datum': 42, 'children': [1, 2]}], 1)
     expected = [
         circ.Circle(r=42.0, ex={'datum': 42, 'children': [1, 2]}),
     ]
     self.assertEqual(expected, actual)
コード例 #8
0
def density(solution):
    """Report density of the solution

    The surface of the circle relative to the enclosure

    """
    circ.circ.scale(solution, circ.Circle(0.0, 0.0, 1.0))
    density = sum(c.r * c.r for c in solution if c.r < 1.0)
    return density
コード例 #9
0
 def test_handle_custom_id_key(self):
     """Specify value as dict with custom keys."""
     actual = circ.circlify([{
         "name": "a2",
         "datum": 0.05
     }],
                            id_field="name")
     expected = [circ.Circle(ex={"name": "a2", "datum": 0.05})]
     self.assertEqual(expected, actual)
コード例 #10
0
 def test_handle_dict_w_children(self):
     actual = circ.circlify([self.data[2]])
     expected = [
         circ.Circle(
             x=0.0,
             y=0.0,
             r=1.0,
             level=1,
             ex={
                 "id": "a0",
                 "datum": 0.8,
                 "children": [0.3, 0.2, 0.2, 0.1]
             },
         ),
         circ.Circle(
             x=0.548583479265826,
             y=0.4560515085667499,
             r=0.28660893460220066,
             level=2,
             ex={"datum": 0.1},
         ),
         circ.Circle(
             x=-0.5063467568453794,
             y=-0.31184906572942,
             r=0.40532624241173565,
             level=2,
             ex={"datum": 0.2},
         ),
         circ.Circle(
             x=-0.14196677995553317,
             y=0.41229503843233234,
             r=0.40532624241173565,
             level=2,
             ex={"datum": 0.2},
         ),
         circ.Circle(
             x=0.3954007222005534,
             y=-0.31184906572942,
             r=0.4964212366341972,
             level=2,
             ex={"datum": 0.3},
         ),
     ]
     self.assertEqual(expected, actual)
コード例 #11
0
def test_results_by_date(conn, min_date, max_date):
    sql = "SELECT resultadoTeste, count(resultadoTeste) FROM dados_covid_mg "
    sql = sql + "WHERE resultadoTeste != \"NULL\" AND dataNotificacao >= \"{min_date_value}\" AND dataNotificacao <= \"{max_date_value}\"  "
    sql = sql + "AND resultadoTeste != \"Inconclusivo ou Indeterminado\"GROUP BY resultadoTeste"

    sql = sql.format(min_date_value=min_date, max_date_value=max_date)

    rs = conn.execute(sql)
    df = DataFrame(rs.fetchall())
    df = df.rename(columns={0: 'Name', 1: 'Value'})

    circles = circlify.circlify(df['Value'].tolist(),
                                show_enclosure=False,
                                target_enclosure=circlify.Circle(x=0, y=0,
                                                                 r=1))

    fig, ax = plt.subplots(figsize=(10, 10))

    ax.set_title('Resultados dos Testes (De ' + min_date + ' à ' + max_date +
                 ')')

    ax.axis('off')

    lim = max(
        max(
            abs(circle.x) + circle.r,
            abs(circle.y) + circle.r,
        ) for circle in circles)
    plt.xlim(-lim, lim)
    plt.ylim(-lim, lim)

    labels = df['Name']

    for circle, label in zip(circles, labels):
        x, y, r = circle
        ax.add_patch(
            plt.Circle((x, y),
                       r * 0.7,
                       alpha=0.9,
                       linewidth=2,
                       facecolor="#69b2a3",
                       edgecolor="black"))
        plt.annotate(label, (x, y),
                     va='center',
                     ha='center',
                     bbox=dict(facecolor='white',
                               edgecolor='black',
                               boxstyle='round',
                               pad=.5))

    plt.show()
コード例 #12
0
 def test_circlify(self):
     """Check the coordinates of the circles returned are expected."""
     actual = circ.circlify(self.data, show_enclosure=True)
     expected = [
         circ.Circle(x=0.0, y=0.0, r=1.0, level=0),
         circ.Circle(
             x=-0.7680630545906644,
             y=0.13661056172475666,
             r=0.21988250795031175,
             level=1,
             ex={"datum": 2},
         ),
         circ.Circle(
             x=-0.4586184780594718,
             y=0.5154819840108337,
             r=0.2692999739208646,
             level=1,
             ex={"datum": 3},
         ),
         circ.Circle(
             x=0.15910532107887837,
             y=-0.6704181394216174,
             r=0.31096082487194077,
             level=1,
             ex={"datum": 4},
         ),
         circ.Circle(
             x=0.15769153632817096,
             y=0.5438978793053209,
             r=0.34766477137653345,
             level=1,
             ex={"datum": 5},
         ),
         circ.Circle(
             x=-0.20976457776763055,
             y=-0.08515409741642607,
             r=0.3808476754656075,
             level=1,
             ex={"datum": 6},
         ),
         circ.Circle(
             x=0.5824456027453089,
             y=-0.08515409741642607,
             r=0.41136250504733196,
             level=1,
             ex={"datum": 7},
         ),
     ]
     self.display(actual, reversed(self.data + [None]))
     self.assertEqual(expected, actual)
コード例 #13
0
ファイル: tests.py プロジェクト: bingxindu/circlify
 def test_circlify(self):
     """Check the coordinates of the circles returned are expected."""
     actual = circ.circlify(self.data, show_enclosure=True)
     self.display(actual, reversed(self.data + [None]))
     expected = [
         circ.Circle(x=0.0, y=0.0, r=1.0, level=0),
         circ.Circle(x=-0.18045635173699437, y=-0.22990093891844118,
                     r=0.051776695296636886),
         circ.Circle(x=-0.42762855855875753, y=-0.6656611405645538,
                     r=0.07322330470336313),
         circ.Circle(x=-0.5170830169797044, y=-0.5131885205024093,
                     r=0.10355339059327377),
         circ.Circle(x=0.10281914590763144, y=-0.662720719883036,
                     r=0.14644660940672627),
         circ.Circle(x=-0.20710678118654763, y=-0.49258571550470814,
                     r=0.20710678118654754),
         circ.Circle(x=-0.2218254069479773, y=0.6062444788590926,
                     r=0.29289321881345254),
         circ.Circle(x=-0.5857864376269051, y=0.0, r=0.4142135623730951),
         circ.Circle(x=0.4142135623730951, y=0.0, r=0.5857864376269051),
     ]
     self.assertEqual(expected, actual)
コード例 #14
0
ファイル: tests.py プロジェクト: bingxindu/circlify
 def test_handle_dict(self):
     """Specify value as a dict."""
     actual = circ.circlify([self.data[1]])
     expected = [circ.Circle(ex={'id': 'a2', 'datum': 0.05})]
     self.assertEqual(expected, actual)
コード例 #15
0
 def test_handle_single_value(self):
     """Typical specification of data with just a value."""
     actual = circ.circlify([self.data[0]])
     expected = [circ.Circle(ex={"datum": 0.05})]
     self.assertEqual(expected, actual)
コード例 #16
0
 def test_json_input(self):
     """Simple json data."""
     actual = circ.circlify(self.data, show_enclosure=True)
     self.display(actual)
     expected = [
         circ.Circle(x=0.0, y=0.0, r=1.0, level=0, ex=None),
         circ.Circle(
             level=1,
             ex={"datum": 0.05},
         ),
         circ.Circle(
             level=1,
             ex={
                 "id": "a2",
                 "datum": 0.05
             },
         ),
         circ.Circle(
             level=1,
             ex={
                 "id":
                 "a1",
                 "datum":
                 0.1,
                 "children": [
                     {
                         "id": "a1_1",
                         "datum": 0.05
                     },
                     {
                         "datum": 0.04
                     },
                     {
                         "id": "a1_2",
                         "datum": 0.01
                     },
                 ],
             },
         ),
         circ.Circle(
             level=1,
             ex={
                 "id": "a0",
                 "datum": 0.8,
                 "children": [0.3, 0.2, 0.2, 0.1]
             },
         ),
         circ.Circle(
             level=2,
             ex={
                 "id": "a1_2",
                 "datum": 0.01
             },
         ),
         circ.Circle(
             level=2,
             ex={"datum": 0.04},
         ),
         circ.Circle(
             level=2,
             ex={
                 "id": "a1_1",
                 "datum": 0.05
             },
         ),
         circ.Circle(
             level=2,
             ex={"datum": 0.1},
         ),
         circ.Circle(
             level=2,
             ex={"datum": 0.2},
         ),
         circ.Circle(
             level=2,
             ex={"datum": 0.2},
         ),
         circ.Circle(
             level=2,
             ex={"datum": 0.3},
         ),
     ]
     actual_level_and_ex = ignore_xyr(actual)
     self.assertEqual(expected, actual_level_and_ex)
コード例 #17
0
 def test_json_input(self):
     """Simple json data."""
     actual = circ.circlify(self.data, show_enclosure=True)
     expected = [
         circ.Circle(x=0.0, y=0.0, r=1.0, level=0, ex=None),
         circ.Circle(
             x=-0.565803075997749,
             y=0.41097786651145324,
             r=0.18469903125906464,
             level=1,
             ex={"datum": 0.05},
         ),
         circ.Circle(
             x=-0.3385727489559141,
             y=0.7022188441650276,
             r=0.18469903125906464,
             level=1,
             ex={
                 "id": "a2",
                 "datum": 0.05
             },
         ),
         circ.Circle(
             x=-0.7387961250362587,
             y=0.0,
             r=0.2612038749637415,
             level=1,
             ex={
                 "id":
                 "a1",
                 "datum":
                 0.1,
                 "children": [
                     {
                         "id": "a1_1",
                         "datum": 0.05
                     },
                     {
                         "datum": 0.04
                     },
                     {
                         "id": "a1_2",
                         "datum": 0.01
                     },
                 ],
             },
         ),
         circ.Circle(
             x=0.2612038749637414,
             y=0.0,
             r=0.7387961250362586,
             level=1,
             ex={
                 "id": "a0",
                 "datum": 0.8,
                 "children": [0.3, 0.2, 0.2, 0.1]
             },
         ),
         circ.Circle(
             x=-0.7567888163564136,
             y=0.14087823651338607,
             r=0.0616618704777984,
             level=2,
             ex={
                 "id": "a1_2",
                 "datum": 0.01
             },
         ),
         circ.Circle(
             x=-0.8766762590444033,
             y=0.0,
             r=0.1233237409555968,
             level=2,
             ex={"datum": 0.04},
         ),
         circ.Circle(
             x=-0.6154723840806618,
             y=0.0,
             r=0.13788013400814464,
             level=2,
             ex={
                 "id": "a1_1",
                 "datum": 0.05
             },
         ),
         circ.Circle(
             x=0.6664952237042423,
             y=0.3369290873460549,
             r=0.2117455702848763,
             level=2,
             ex={"datum": 0.1},
         ),
         circ.Circle(
             x=-0.11288314691830154,
             y=-0.230392881357073,
             r=0.2994534572692975,
             level=2,
             ex={"datum": 0.2},
         ),
         circ.Circle(
             x=0.15631936804871832,
             y=0.30460197676548245,
             r=0.2994534572692975,
             level=2,
             ex={"datum": 0.2},
         ),
         circ.Circle(
             x=0.5533243963620484,
             y=-0.230392881357073,
             r=0.36675408601105247,
             level=2,
             ex={"datum": 0.3},
         ),
     ]
     self.display(actual)
     self.assertEqual(expected, actual)
コード例 #18
0
 def test_dict_w_datum_only(self):
     """Handles dict with just the data"""
     actual = circ._handle([{"datum": 42}], 1)
     self.assertEqual([circ.Circle(r=42, ex={"datum": 42})], actual)
コード例 #19
0
 def test_repr_and_str_with_id_(self):
     """Check str() and repr() conversion"""
     expected = "Circle(x=0.0, y=0.0, r=2.0, level=1, " "ex={'label': '3'})"
     actual = str(circ.Circle(r=2.0, ex={"label": "3"}))
     self.assertEqual(expected, actual)
コード例 #20
0
 def test_integer(self):
     """handles integer"""
     actual = circ._handle([42], 1)
     self.assertEqual([circ.Circle(r=42, ex={"datum": 42})], actual)
コード例 #21
0
 def test_degenerate_inner_completely_inside_outer_circle(self):
     """Testing case where degenerate inner is completely inside the outer circle."""
     c1 = circ.Circle(0, 0, 0)
     c2 = circ.Circle(0, 0, 1)
     self.assertEqual(circ.get_intersection(c1, c2), (None, None))
コード例 #22
0
 def test_single_value(self):
     """If there is only one value, it should occupy the whole circle."""
     actual = circ.circlify([2.0])
     expected = [circ.Circle(r=1.0, ex={"datum": 2.0})]
     self.assertEqual(actual, expected)
    oval(x - r, y - r, diam, diam)


W = 4000
H = 4000
margins = 100
newPage(W, H)

fill(0, 0, 0, 1)
rect(0, 0, W, H)
fill(1, 0, 0, 1)

circles = circ.circlify([diametersList],
                        id_field='id',
                        datum_field='q',
                        target_enclosure=circ.Circle(0, 0, .95),
                        show_enclosure=False)

for c in circles:
    if not 'char' in c.ex: continue
    char = c.ex['char']
    if char == "":
        fill(None)
    elif not 'children' in c.ex:
        l = c.ex['l'] / 6
        s = 1 - 6 * (c.ex['q'] / maxDiam)
        if char in lvl1:
            color = colorsys.hsv_to_rgb(l, s, 1)
        elif char in lvl2:
            color = colorsys.hsv_to_rgb(l, s, 1)
        elif char in lvl3:
コード例 #24
0
 def test_repr_and_str_with_circle(self):
     """Check str() and repr() conversion"""
     expected = "Circle(x=0.0, y=0.0, r=1.0, level=1, ex=None)"
     self.assertEqual(expected, str(circ.Circle()))
コード例 #25
0
 def test_handle_dict(self):
     """Specify value as a dict."""
     actual = circ.circlify([self.data[1]])
     expected = [circ.Circle(ex={"id": "a2", "datum": 0.05})]
     self.assertEqual(expected, actual)
コード例 #26
0
 def test_float(self):
     """Handles float."""
     actual = circ._handle([42.0], 1)
     self.assertEqual([circ.Circle(r=42.0, ex={"datum": 42.0})], actual)
コード例 #27
0
 def test_equality_with_ex(self):
     """Check equality with extended info."""
     self.assertNotEqual(circ.Circle(), circ.Circle(ex={"test": 0}))
コード例 #28
0
 def test_edge_cases(self, x1, y1, r1, x2, y2, r2):
     """Edge cases do not cause exceptions."""
     c1 = circ.Circle(x=x1, y=y1, r=r1)
     c2 = circ.Circle(x=x2, y=y2, r=r2)
     self.assertIsNotNone(circ.get_intersection(c1, c2))
def drawCircleFromCenter(x, y, diam):
    r = diam / 2
    oval(x-r, y-r, diam, diam)

W = 4000
H = 4000
margins = 100
newPage(W, H)

fill(0, 0, 0, 1)
rect(0, 0, W, H)
fill(1, 0, 0, 1)

diametersList = diametersList
circles = circ.circlify(diametersList, id_field='id', datum_field='q', target_enclosure=circ.Circle(0, 0, .8), show_enclosure=False)

maxc = max([c.r for c in circles])
divide = 1.3
divideMore = 3
for c in circles:
    char = c.ex['char']
    if char == "":
        fill(None)
    elif not 'children' in c.ex:
        colred = ((c.ex['q'])/(maxDiam))/divide
        colgreen = ((c.ex['q'])/(maxDiam))/divide
        colblue = ((c.ex['q'])/(maxDiam))/divide
        
        fill(colred, colgreen, colblue, 1)
        
コード例 #30
0
 def test_unpack(self):
     """Circle should unpack to tuples."""
     x, y, r = circ.Circle(1, 2, 3)
     self.assertEqual((x, y, r), (1, 2, 3))