def run(self, save=True): df = self._get_data_frame() formula = self.get_formula() self.results = self.fit(df, formula) if save: Forecaster.create_from_regressor(self, name=self.forecaster_name) return self.results
def view_forecaster(request, forecaster_id): member = request.user.member try: forecaster = Forecaster.get_all_from_member(member).get( id=forecaster_id) except Forecaster.DoesNotExist: raise Http404 return render(request, "forecasters/view.html", { "forecaster": forecaster, "member": member })
def get_forecasters(self): current_request = CrequestMiddleware.get_request() current_user = current_request.user forecasters = Forecaster.get_all_from_member(current_user.member) if self.cleaned_data.get("board"): forecasters = forecasters.filter( board=self.cleaned_data.get("board")) if self.cleaned_data.get("member"): forecasters = forecasters.filter( member=self.cleaned_data.get("member")) if self.cleaned_data.get("model"): forecasters = forecasters.filter( model=self.cleaned_data.get("model")) return forecasters.order_by("board", "member", "model")
def test_forecaster(request, forecaster_id): member = request.user.member try: forecaster = Forecaster.get_all_from_member(member).get( id=forecaster_id) except Forecaster.DoesNotExist: raise Http404 if request.method == "POST": form = TestForecasterForm(request.POST) if form.is_valid(): test_cards = forecaster.test_cards total_error = 0 test_card_errors = [] for test_card in test_cards: test_card_estimated_spent_time = float( forecaster.estimate_spent_time(test_card)) test_card.estimated_spent_time = Decimal( test_card_estimated_spent_time).quantize(Decimal('1.000')) test_card.diff = test_card.spent_time - test_card.estimated_spent_time test_card.error = abs(test_card.diff) total_error += test_card.error test_card_errors.append(test_card.error) avg_error = np.mean(test_card_errors) std_dev_error = np.std(test_card_errors) replacements = { "form": form, "forecaster": forecaster, "test_cards": test_cards, "total_error": total_error, "avg_error": avg_error, "std_dev_error": std_dev_error, "member": member } return render(request, "forecasters/test.html", replacements) else: form = TestForecasterForm() return render(request, "forecasters/test.html", { "form": form, "member": member, "forecaster": forecaster })
def update_forecaster(request, forecaster_id): member = request.user.member try: forecaster = Forecaster.get_all_from_member(member).get( id=forecaster_id) except Forecaster.DoesNotExist: raise Http404 if request.method == "POST": form = UpdateForecasterForm(request.POST) if form.is_valid(): form.save(forecaster) return HttpResponseRedirect(reverse("forecasters:index")) else: form = UpdateForecasterForm() return render(request, "forecasters/update.html", { "form": form, "forecaster": forecaster, "member": member })
def index(request): member = request.user.member form = FilterForecastersForm(request.GET) replacements = {"member": member, "form": form} template_path = "forecasters/index/without_board.html" if form.is_valid(): forecasters = form.get_forecasters() user_boards = get_user_boards(request.user) if form.cleaned_data.get("board") and user_boards.filter( id=form.cleaned_data.get("board")).exists(): board = user_boards.get(id=form.cleaned_data.get("board")) replacements["board"] = board template_path = "forecasters/index/with_board.html" else: forecasters = Forecaster.get_all_from_member(member) replacements["forecasters"] = forecasters return render(request, template_path, replacements)
def get_queryset(self): member = self.request.user.member return Forecaster.get_all_from_member(member)