コード例 #1
0
 def test_example_input(self):
     chart = SeatingChart(3, 11)
     chart.initialize([(1, 4), (1, 6), (2, 3), (2, 7), (3, 9), (3, 10)])
     chart._find_seats(3)
     chart._find_seats(3)
     chart._find_seats(3)
     chart._find_seats(1)
     chart._find_seats(10)
     expected = {
         300002: 1,
         400001: 1,
         400002: 1,
         500001: 1,
         500002: 1,
         500003: 1,
         600001: 1,
         600002: 1,
         600003: 1,
         700001: 1,
         700002: 1,
         700003: 1,
         800001: 1,
         900001: 1,
         900003: 1,
         1000003: 1
     }
     actual = chart._reserved_seats
     assert expected == actual
コード例 #2
0
 def test_adjacency_layers(self):
     """
     Ensures that the adjacency layers function is working correctly.
     """
     seats = SeatingChart('data/test-seats-complex.csv')
     self.assertEqual(
         [{'*****@*****.**', '*****@*****.**'},
          set(), set()],
         list(
             seats.adjacency_layers('*****@*****.**', 3,
                                    AdjacencyType.sideways_only)))
コード例 #3
0
 def test_adjacency(self):
     """
     Test of adjacency, from sample seating chart.
     """
     seats = SeatingChart('data/test-seats-complex.csv')
     self.assertEqual({"*****@*****.**", "*****@*****.**"},
                      set(
                          seats.adjacent_to("*****@*****.**",
                                            AdjacencyType.all_ways)))
     self.assertEqual(
         {"*****@*****.**", "*****@*****.**", "*****@*****.**"},
         set(seats.adjacent_to("*****@*****.**", AdjacencyType.all_ways)))
     self.assertEqual(
         set(),
         set(seats.adjacent_to("*****@*****.**", AdjacencyType.all_ways)),
         "Nothing adjacent to something in a different room")
コード例 #4
0
 def test_create_new_seating_chart(self):
     chart = SeatingChart(10, 11)
     assert isinstance(chart, SeatingChart)
     assert chart._rows == 10
     assert chart._cols == 11
     assert chart._reserved_seats == {}
     assert chart.sold_out == False
     assert chart.number_reserved == 0
     assert chart.number_available == 10 * 11
コード例 #5
0
ファイル: profile.py プロジェクト: kavigupta/61a-analysis
def main(arg):
    """
    The profiling test
    """
    evals = proc_evaluations('%s/real-data/Midterm_1_evaluations.zip' % DATA_DIR)
    seats = SeatingChart('%s/real-data/mt1_seats.csv' % DATA_DIR)
    if arg == "--plausible-params":
        profile_plausible_params(evals, seats)
    else:
        raise RuntimeError("Argument %s not recognized" % arg)
コード例 #6
0
ファイル: reporting.py プロジェクト: kavigupta/61a-analysis
def load_all():
    """
    Return evaluations, seats, and zero_meaned evaluations from each of the results.
    """
    evals = OrderedDict()
    seats = OrderedDict()
    zero_meaneds = OrderedDict()
    zero_meaned_no_correction = OrderedDict()
    for exam in "mt1", "mt2", "final":
        evals[exam] = proc_evaluations('%s/real-data/%s_evaluations.zip' %
                                       (DATA_DIR, exam))
        seats[exam] = SeatingChart('%s/real-data/%s_seats.csv' %
                                   (DATA_DIR, exam))
        zero_meaneds[exam] = compensate_for_grader_means(evals[exam])
        zero_meaned_no_correction[exam] = compensate_for_grader_means(
            evals[exam], z_thresh=float('inf'))
    return evals, seats, zero_meaneds, zero_meaned_no_correction
コード例 #7
0
 def test_column_normalization(self):
     """
     Makes sure that column normalization is carried out on a per-room basis.
     """
     seats = SeatingChart('data/test-seats-multiroom.csv')
     self.assertEqual({"*****@*****.**", "*****@*****.**"},
                      set(
                          seats.adjacent_to("*****@*****.**",
                                            AdjacencyType.all_ways)))
     self.assertEqual(
         {"*****@*****.**", "*****@*****.**", "*****@*****.**"},
         set(seats.adjacent_to("*****@*****.**", AdjacencyType.all_ways)))
     self.assertEqual({"*****@*****.**", "*****@*****.**"},
                      set(
                          seats.adjacent_to("*****@*****.**",
                                            AdjacencyType.all_ways)))
     # pylint: disable=W0212
     self.assertEqual(0.5,
                      seats._location("*****@*****.**").column.location)
コード例 #8
0
 def test_find_best_five_seats_in_second_row(self):
     chart = SeatingChart(5, 10)
     chart.initialize([(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6),
                       (1, 7), (1, 8), (1, 9), (1, 10)])
     chart._find_seats(5)
     expected = {
         400001: 1,
         200001: 1,
         100001: 1,
         900001: 1,
         700001: 1,
         600001: 1,
         500001: 1,
         300001: 1,
         1000001: 1,
         800001: 1,
         300002: 1,
         400002: 1,
         500002: 1,
         600002: 1,
         700002: 1
     }
     actual = chart._reserved_seats
     assert expected == actual
コード例 #9
0
 def test_find_best_four_seats_in_empty_row_of_odd_columns(self):
     chart = SeatingChart(1, 9)
     chart._find_seats(4)
     expected = {300001: 1, 400001: 1, 500001: 1, 600001: 1}
     actual = chart._reserved_seats
     assert expected == actual
コード例 #10
0
Tests for various modules.
"""
from unittest import TestCase, main

from numpy.testing import assert_almost_equal as aae

from seating_chart import SeatingChart, Location, AdjacencyType
from constants import DATA_DIR
from evaluations import proc_evaluations
from analytics import compensate_for_grader_means, all_pairs, ExamPair, _unusualness
from graded_exam import ExamQuestion
from graphics import NoProgressBar

EVALS_SAMPLE = proc_evaluations('data/test-evals.zip')
EVALS_SIMPLE_SAMPLE = proc_evaluations('data/test-simple-evals.zip')
SEATS_SAMPLE = SeatingChart('data/test-seats.csv')
SEATS_SIMPLE_SAMPLE = SeatingChart('data/test-seats-simple.csv')


class TestAnalytics(TestCase):
    """
    Test suite for analytics.py.
    """
    @staticmethod
    def test_compensate_for_grader_means():  # pylint: disable=C0103
        """
        Tests the compensate_for_grader_means function (only the compensation, not the filtering)
            by running it on a sample and testing two individuals to check that they were adjusted
            appropriately.
        """
        compensated = compensate_for_grader_means(EVALS_SAMPLE, 1000)
コード例 #11
0
 def test_reserving_a_seat_twice(self):
     chart = SeatingChart(5, 5)
     chart.reserve((2, 8))
     expected = None
     actual = chart.reserve((2, 8))
     assert actual == expected
コード例 #12
0
 def test_group_bigger_than_a_row(self):
     chart = SeatingChart(10, 6)
     expected = None
     actual = chart._find_seats(7)
     assert actual == expected
コード例 #13
0
 def test_get_taxi_even_cols(self):
     chart = SeatingChart(5, 10)
     left = chart._get_taxi((4, 9))
     right = chart._get_taxi((4, 2))
     assert left == right
コード例 #14
0
 def test_reserving_a_seat_once(self):
     chart = SeatingChart(5, 5)
     expected = [(2, 5)]
     actual = chart.reserve((2, 5))
     assert actual == expected
コード例 #15
0
 def test_cant_change_hash_formula_by_accident(self):
     chart = SeatingChart(10, 11)
     assert chart._get_key(12, 23) == 2300012
コード例 #16
0
 def test_no_space_left_for_group(self):
     chart = SeatingChart(2, 6)
     chart.initialize([(1, 1), (1, 3), (1, 5), (2, 2), (2, 4), (2, 6)])
     expected = None
     actual = chart._find_seats(2)
     assert actual == expected
コード例 #17
0
 def test_unreserved_seat_is_marked_unreserved(self):
     chart = SeatingChart(5, 5)
     expected = False
     actual = chart.reserved((1, 3))
     assert actual == expected
コード例 #18
0
 def test_initializing_with_out_of_bound_values(self):
     chart = SeatingChart(5, 5)
     with pytest.raises(KeyError):
         chart.initialize([(1, 2), (1, 7)])
コード例 #19
0
class TestSeatingChart(TestCase):
    """
    Tests seating charts
    """
    chart = SeatingChart('{}/real-data/mt1_seats.csv'.format(DATA_DIR))

    def test_exist_emails(self):
        """
        Test that the emails all exist and are strings.
        """
        for email in self.chart.emails:
            self.assertEqual(type(email), str)

    def test_adjacency_consistency(self):
        """
        Test to make sure that X is right of Y <--> Y is left of X
        """
        for email in self.chart.emails:
            for adj_email in self.chart.sideways_items(email):
                adj_adj_email = self.chart.sideways_items(adj_email)
                self.assertTrue(email in adj_adj_email, str(
                    (email, adj_email)))

    def test_adjacency(self):
        """
        Test of adjacency, from sample seating chart.
        """
        seats = SeatingChart('data/test-seats-complex.csv')
        self.assertEqual({"*****@*****.**", "*****@*****.**"},
                         set(
                             seats.adjacent_to("*****@*****.**",
                                               AdjacencyType.all_ways)))
        self.assertEqual(
            {"*****@*****.**", "*****@*****.**", "*****@*****.**"},
            set(seats.adjacent_to("*****@*****.**", AdjacencyType.all_ways)))
        self.assertEqual(
            set(),
            set(seats.adjacent_to("*****@*****.**", AdjacencyType.all_ways)),
            "Nothing adjacent to something in a different room")

    def test_column_normalization(self):
        """
        Makes sure that column normalization is carried out on a per-room basis.
        """
        seats = SeatingChart('data/test-seats-multiroom.csv')
        self.assertEqual({"*****@*****.**", "*****@*****.**"},
                         set(
                             seats.adjacent_to("*****@*****.**",
                                               AdjacencyType.all_ways)))
        self.assertEqual(
            {"*****@*****.**", "*****@*****.**", "*****@*****.**"},
            set(seats.adjacent_to("*****@*****.**", AdjacencyType.all_ways)))
        self.assertEqual({"*****@*****.**", "*****@*****.**"},
                         set(
                             seats.adjacent_to("*****@*****.**",
                                               AdjacencyType.all_ways)))
        # pylint: disable=W0212
        self.assertEqual(0.5,
                         seats._location("*****@*****.**").column.location)

    def test_adjacency_layers(self):
        """
        Ensures that the adjacency layers function is working correctly.
        """
        seats = SeatingChart('data/test-seats-complex.csv')
        self.assertEqual(
            [{'*****@*****.**', '*****@*****.**'},
             set(), set()],
            list(
                seats.adjacency_layers('*****@*****.**', 3,
                                       AdjacencyType.sideways_only)))
コード例 #20
0
 def test_reserve_takes_only_strs_or_ints(self):
     chart = SeatingChart(5, 5)
     with pytest.raises(ValueError):
         chart.reserve(4.5)
コード例 #21
0
ファイル: script.py プロジェクト: kavigupta/61a-analysis
def one_way_vs_two_way_summary_correlation(grades, seats):
    """
    Produces differences in the correlations between one-apart and two-apart individuals.
    """
    return one_way_vs_two_way_summary(
        grades,
        seats,
        gambler_fallacy_allowable_limit=GAMBLER_FALLACY_ALLOWABLE_LIMIT,
        similarity_fn=lambda x, y: x.correlation(y))


GAMBLER_FALLACY_ALLOWABLE_LIMIT = 1

EVALS = proc_evaluations('%s/real-data/mt1_evaluations.zip' % DATA_DIR)
SEATS = SeatingChart('%s/real-data/mt1_seats.csv' % DATA_DIR)

MODEL = binary_cheater(RandomSeatingModel, (), AdjacencyType.sideways_only)

TRUE_VALUE = one_way_vs_two_way_summary_correlation(EVALS, SEATS)

PARAMS = list((cheaters, ratio)
              for cheaters, ratio in MODEL.parameters(GRANULARITY)
              if cheaters < 0.3)


def proc_param(param):
    """
    Process the given parameter
    """
    result = model_on_params(EVALS,
コード例 #22
0
 def test_find_best_five_seats_in_empty_row_of_even_columns(self):
     chart = SeatingChart(1, 10)
     chart._find_seats(5)
     expected = {300001: 1, 400001: 1, 500001: 1, 600001: 1, 700001: 1}
     actual = chart._reserved_seats
     assert expected == actual
コード例 #23
0
 def test_get_taxi_odd_cols(self):
     chart = SeatingChart(5, 9)
     left = chart._get_taxi((4, 8))
     right = chart._get_taxi((4, 2))
     assert left == right
コード例 #24
0
 def test_reserved_seat_is_marked_reserved(self):
     chart = SeatingChart(5, 5)
     chart.reserve((1, 3))
     expected = True
     actual = chart.reserved((1, 3))
     assert actual == expected
コード例 #25
0
 def test_row_not_wide_enough(self):
     chart = SeatingChart(5, 5)
     expected = None
     actual = driver.additional_reservation(chart, "10")
     assert actual == expected