コード例 #1
0
 def test_graph_scale_missing_values(self):
     test_data = [
         dict(fob_price=3.12345678,
              landed_price=None,
              country="South Africa"),
         dict(fob_price=None, landed_price=4.12345678, country="Namibia")
     ]
     test_graph = FormulationGraph(test_data, None)
     # round up from 4.123 to 5
     self.assertAlmostEquals(5.0, test_graph.max_price)
コード例 #2
0
    def test_graph_medians(self):
        data = self.raw_data[:]
        graph = FormulationGraph(data, 2.5643865)
        scale = graph.max_price

        # even number of data points, should average the middle two
        html = graph.as_html()
        self.assertBar(html, "msh_price", 2.564, scale, 2)
        self.assertBar(html, "median_fob_price",
                       (3.12345678 + 4.12345678) / 2.0, scale, 2)
        self.assertBar(html, "median_landed_price",
                       (4.98765432 + 5.98765432) / 2.0, scale, 2)

        # odd number of data points, should use the middle one
        data.append(
            dict(fob_price=5.36789549,
                 landed_price=5.5367875,
                 country="Upper Eureka"))
        graph = FormulationGraph(data, 2.5643865)
        self.assertAlmostEquals(10.0, graph.max_price)
        html = graph.as_html()
        self.assertBar(html, "msh_price", 2.564, scale, 2)
        self.assertBar(html, "median_fob_price", 4.12345678, scale, 2)
        self.assertBar(html, "median_landed_price", 5.5367875, scale, 2)

        # some values missing
        data.append(
            dict(fob_price=3.7854638,
                 landed_price=None,
                 country="Lower Eureka"))
        data.append(
            dict(fob_price=None, landed_price=6.3476238, country="Ambata"))
        # fobs = 3.12345678, 3.7854638, 4.12345678, 5.36789549
        # landed = 4.98765432, 5.5367875, 5.98765432, 6.3476238
        graph = FormulationGraph(data, 2.5643865)
        self.assertAlmostEquals(10.0, graph.max_price)
        html = graph.as_html()
        self.assertBar(html, "msh_price", 2.564, scale, 2)
        self.assertBar(html, "median_fob_price",
                       (3.7854638 + 4.12345678) / 2.0, scale, 2)
        self.assertBar(html, "median_landed_price",
                       (5.5367875 + 5.98765432) / 2.0, scale, 2)
コード例 #3
0
    def setUp(self):
        self.raw_data = [
            dict(fob_price=3.12345678,
                 landed_price=4.98765432,
                 country="South Africa"),
            dict(fob_price=4.12345678,
                 landed_price=5.98765432,
                 country="Namibia")
        ]

        self.formulation_graph = FormulationGraph(self.raw_data)
        rows = self.formulation_graph.rows
        self.first_row = rows[self.FIRST_ROW]
コード例 #4
0
def formulation(request, formulation_id, backend_name="django"):
    backend = get_backend(backend_name)

    drug_searcher = DrugSearcher(backend)
    rows = drug_searcher.get_prices_for_formulation_with_id(formulation_id)

    # Don't like that, but results is being changed in the constructor of the table.
    rows_graph = deepcopy(rows)

    formulation_name = drug_searcher.get_formulation_name_with_id(
        formulation_id)
    formulation_msh = drug_searcher.get_formulation_msh_with_id(formulation_id)

    formulation_table = FormulationTable(rows)
    formulation_graph = FormulationGraph(rows_graph, formulation_msh)

    search_form = SearchForm()

    products_href = reverse('formulation_products',
                            args=[str(formulation_id), backend_name])
    formulation_tab = get_formulation_tab(None)
    similar_products_tab = get_similar_products_tab(products_href)
    menu = Menu([formulation_tab, similar_products_tab])

    price_popups = []
    for price_fields in rows:
        price_popups.append(PricePopup(price_fields))

    return render_to_response(
        'formulation.html', {
            'formulation_table': formulation_table,
            'formulation_graph': formulation_graph,
            'formulation_msh': formulation_msh,
            'price_popups': price_popups,
            'menu': menu,
            'search_form': search_form,
            'sub_title': "Formulation",
            'sub_sub_title': formulation_name
        }, RequestContext(request))
コード例 #5
0
 def test_graph_scale_rounding(self):
     self.assertAlmostEquals(0.001, FormulationGraph([], 0.0003).max_price)
     self.assertAlmostEquals(0.001, FormulationGraph([], 0.0005).max_price)
     self.assertAlmostEquals(0.001, FormulationGraph([], 0.0007).max_price)
     self.assertAlmostEquals(0.001, FormulationGraph([], 0.001).max_price)
     self.assertAlmostEquals(0.1, FormulationGraph([], 0.099).max_price)
     self.assertAlmostEquals(0.1, FormulationGraph([], 0.1).max_price)
     self.assertAlmostEquals(0.2, FormulationGraph([], 0.101).max_price)
     self.assertAlmostEquals(0.2, FormulationGraph([], 0.199).max_price)
     self.assertAlmostEquals(0.2, FormulationGraph([], 0.2).max_price)
     self.assertAlmostEquals(0.5, FormulationGraph([], 0.201).max_price)
     self.assertAlmostEquals(1.0, FormulationGraph([], 0.99).max_price)
     self.assertAlmostEquals(1.0, FormulationGraph([], 1.0).max_price)
     self.assertAlmostEquals(2.0, FormulationGraph([], 1.01).max_price)
     self.assertAlmostEquals(2.0, FormulationGraph([], 1.99).max_price)
     self.assertAlmostEquals(2.0, FormulationGraph([], 2.0).max_price)
     self.assertAlmostEquals(5.0, FormulationGraph([], 4.99).max_price)
     self.assertAlmostEquals(5.0, FormulationGraph([], 5.0).max_price)
     self.assertAlmostEquals(10.0, FormulationGraph([], 5.01).max_price)
     self.assertAlmostEquals(10.0, FormulationGraph([], 9.99).max_price)
     self.assertAlmostEquals(100.0, FormulationGraph([], 50.01).max_price)
     self.assertAlmostEquals(100.0, FormulationGraph([], 99.99).max_price)
     self.assertAlmostEquals(100.0, FormulationGraph([], 100.0).max_price)
コード例 #6
0
 def test_graph_scale_works_with_decimal_msh(self):
     test_graph = FormulationGraph(self.raw_data, Decimal('0.4577901'))
     # round up from 5.988 to 10
     self.assertAlmostEquals(10.0, test_graph.max_price)
コード例 #7
0
 def test_graph_scale_includes_msh_price(self):
     test_graph = FormulationGraph(self.raw_data, 16.075127)
     # round up from 16.075 to 20
     self.assertAlmostEquals(20.0, test_graph.max_price)