Exemplo n.º 1
0
def ateams_info(request):
    context = {}
    context['BUST'] = cache_bust()
    role = None
    st = None
    pos = 0
    team_type = 0
    response = Http404
    if request.user.is_authenticated:
        st = SessionTeam.objects.filter(
            Q(session__status__in=Session.ACTIVE_STATES)
            & Q(team=request.user.profile.team)).first()
        if st:
            context = get_cutsom_links(request, st, context)
            context['state'] = st.session.status

            response = HttpResponse(render(request, "info.html", context))
            response.set_cookie('username', request.user.username)
            response.set_cookie('use_ai', st.session.use_ai)
        else:
            response = HttpResponse(render(request, "info.html"))
            response.set_cookie('username', request.user.username)
    else:
        response = Http404
    return response
Exemplo n.º 2
0
def ateams_process(request):
    context = {}
    context['BUST'] = cache_bust()
    response = None
    if request.user.is_authenticated:
        st = SessionTeam.objects.filter(
            Q(session__status__in=Session.ACTIVE_STATES)
            & Q(team=request.user.profile.team)).first()
        if st:
            if st.session.status == Session.RUNNING:
                context = Interventions.add_intervention_constants(context)
                context['INTER_SEG_NUM'] = settings.INTER_SEG_NUM
                context['INTER_SEG_LEN'] = settings.INTER_SEG_LEN
                response = HttpResponse(
                    render(request, "intervention.html", context))
            else:
                if st.session.status == Session.SETUP:
                    context['redir'] = "/setup/"
                elif st.session.status == Session.PRESESSION:
                    context['redir'] = "/presession/"
                elif st.session.status == Session.POSTSESSION:
                    context['redir'] = "/postsession/"
                context = Interventions.add_intervention_constants(context)
                response = HttpResponse(
                    render(request, "intervention.html", context))
        else:
            context['redir'] = "/"
            context = Interventions.add_intervention_constants(context)
            response = HttpResponse(
                render(request, "intervention.html", context))
    else:
        response = HttpResponse(render(request, "home.html"))
    return response
Exemplo n.º 3
0
def ateams_business(request):
    context = {}
    context['BUST'] = cache_bust()
    response = None
    if request.user.is_authenticated:
        st = SessionTeam.objects.filter(
            Q(session__status__in=Session.ACTIVE_STATES)
            & Q(team=request.user.profile.team)).first()
        if st:
            if st.session.status == Session.RUNNING:
                response = HttpResponse(render(request, "business.html"))
                response.set_cookie('use_ai', st.session.use_ai)
                response.set_cookie('username', request.user.username)
            else:
                if st.session.status == Session.SETUP:
                    context['redir'] = "/setup/"
                elif st.session.status == Session.PRESESSION:
                    context['redir'] = "/presession/"
                elif st.session.status == Session.POSTSESSION:
                    context['redir'] = "/postsession/"
                response = HttpResponse(
                    render(request, "business.html", context))
        else:
            context['redir'] = "/"
            response = HttpResponse(render(request, "business.html", context))
    else:
        response = HttpResponse(render(request, "home.html"))
    return response
Exemplo n.º 4
0
def ateams_temp_user_info(request):
    context = {}
    context['BUST'] = cache_bust()
    user_info = {}
    if request.user.is_authenticated:
        if request.user.profile and request.user.profile.is_experimenter():
            profile = request.user.profile
            organization = profile.organization
            if organization:
                org_teams = DesignTeam.objects.filter(
                    organization=profile.organization)
                for team in org_teams:
                    user_profiles = Profile.objects.filter(team=team)
                    for user_profile in user_profiles:
                        up_user = user_profile.user
                        if user_profile.is_player():
                            user_info[
                                up_user.username] = user_profile.temp_code
                sorted_user_info = collections.OrderedDict()
                for key, value in sorted(user_info.items()):
                    sorted_user_info[key] = value
                context["user_info"] = sorted_user_info
                return HttpResponse(
                    render(request, "tempuserinfo.html", context))
    return HttpResponse(render(request, "home.html"))
Exemplo n.º 5
0
def digital_twin(request, session_id):
    if request.user.is_authenticated and request.user.profile.is_experimenter(
    ):
        session = Session.objects.filter(id=session_id).first()
        digital_twin_setups = get_digital_twin_for_session(session_id)
        context = {
            'session': session,
            'session_id': session_id,
            'digital_twin_setups': digital_twin_setups
        }
        context['BUST'] = cache_bust()
        response = HttpResponse(
            render(request, "digitaltwinedit.html", context))
    else:
        response = HttpResponse(
            render(request, "digitaltwinedit.html", context))
    return response
Exemplo n.º 6
0
def ateams_homepage(request):
    context = {}
    context['BUST'] = cache_bust()
    response = None
    experimenter = False
    if request.user.is_authenticated:
        experimenter = request.user.profile.is_experimenter()
        context['experimenter'] = experimenter
        st = SessionTeam.objects.filter(
            Q(session__status__in=Session.ACTIVE_STATES)
            & Q(team=request.user.profile.team)).first()
        if st:
            up = UserPosition.objects.filter(
                Q(user=request.user) & Q(session=st.session)).first()
            if up:
                if st.session.status == Session.SETUP:
                    context['redir'] = "/setup/"
                elif st.session.status == Session.PRESESSION:
                    context['redir'] = "/presession/"
                elif st.session.status == Session.RUNNING:
                    position = UserPosition.objects.filter(
                        Q(session=st.session)
                        & Q(user=request.user)).first().position
                    if position:
                        if position.role.name == "Business":
                            context['redir'] = "/business/"
                        elif position.role.name == "OpsPlanner":
                            context['redir'] = "/ops/"
                        elif position.role.name == "Designer":
                            context['redir'] = "/design/"
                        elif position.role.name == "Process":
                            context['redir'] = "/process/"
                elif st.session.status == Session.POSTSESSION:
                    context['redir'] = "/postsession/"
                response = HttpResponse(render(request, "home.html", context))
            else:
                # User in team, but not assigned a role, so boot them
                logout(request)
                response = HttpResponse(render(request, "home.html"))
        else:
            if not experimenter:
                logout(request)
            response = HttpResponse(render(request, "home.html", context))
    else:
        response = HttpResponse(render(request, "home.html"))
    return response
Exemplo n.º 7
0
def ateams_setup(request):
    context = {}
    context['BUST'] = cache_bust()
    response = None
    if request.user.is_authenticated:
        st = SessionTeam.objects.filter(
            Q(session__status__in=Session.ACTIVE_STATES)
            & Q(team=request.user.profile.team)).first()
        if st:
            context = get_cutsom_links(request, st, context)

            if st.session.status == Session.SETUP:
                is_team = True
                if st.session.structure.name == "Extra":
                    is_team = False
                context['is_team'] = is_team
                response = HttpResponse(render(request, "setup.html", context))
                response.set_cookie('use_ai', st.session.use_ai)
                response.set_cookie('username', request.user.username)
            else:
                if st.session.status == Session.PRESESSION:
                    context['redir'] = "/presession/"
                elif st.session.status == Session.RUNNING:
                    position = UserPosition.objects.filter(
                        Q(session=st.session)
                        & Q(user=request.user)).first().position
                    if position:
                        if position.role.name == "Business":
                            context['redir'] = "/business/"
                        elif position.role.name == "OpsPlanner":
                            context['redir'] = "/ops/"
                        elif position.role.name == "Designer":
                            context['redir'] = "/design/"
                        elif position.role.name == "Process":
                            context['redir'] = "/process/"
                elif st.session.status == Session.POSTSESSION:
                    context['redir'] = "/postsession/"
                response = HttpResponse(render(request, "setup.html", context))
        else:
            context['redir'] = "/"
            # logout(request)
            response = HttpResponse(render(request, "setup.html", context))
    else:
        response = HttpResponse(render(request, "home.html"))
    return response
Exemplo n.º 8
0
def ateams_experiment_chat(request):
    if request.user.is_authenticated and request.user.profile.is_experimenter(
    ):

        template_sessions = None
        template_sessions = Session.objects.filter(status=Session.TEMPLATE)

        profile = request.user.profile
        org_teams = None
        exp_sessions = None
        session_teams = None
        st_dict = {}
        if profile.organization:
            org_teams = DesignTeam.objects.filter(
                organization=profile.organization)
            org_teams_ids = org_teams.values('id')
            session_teams = SessionTeam.objects.filter(
                team_id__in=org_teams_ids)
            exp_sessions = Session.objects.filter(
                Q(id__in=session_teams.values('session_id'))
                & Q(status__in=Session.ACTIVE_STATES)).order_by('id')
            for st in session_teams:
                st_dict[st.session_id] = DesignTeam.objects.filter(
                    id=st.team_id).first()

        context = {
            'template_sessions': template_sessions,
            'org_teams': org_teams,
            'exp_sessions': exp_sessions,
            'session_teams': session_teams,
            'st_dict': st_dict,
        }
        context['BUST'] = cache_bust()
        response = HttpResponse(render(request, "experimentchat.html",
                                       context))
        if request.user.is_authenticated:
            response.set_cookie('username', request.user.username)
    else:
        response = HttpResponse(render(request, "home.html"))
    return response
Exemplo n.º 9
0
def ateams_experiment(request):
    if request.user.is_authenticated and request.user.profile.is_experimenter(
    ):
        # If any of these are null, go to the organization page to select them
        if not request.user.profile.organization or not request.user.profile.study or not request.user.profile.experiment:
            context = {}
            context['BUST'] = cache_bust()
            orgs = []
            exper_orgs = ExperOrg.objects.filter(user=request.user)
            for exper_org in exper_orgs:
                orgs.append(exper_org.organization)
            context["orgs"] = orgs
            response = HttpResponse(
                render(request, "organization.html", context))
        else:
            profile = request.user.profile
            organization = None
            study = None
            experiment = None
            org_teams = None
            session_teams = None
            markets = None
            structures = None
            st_dict = {}
            session_next = {}
            all_users = dict()
            exercises = {}
            archived_exercises = {}

            if profile.organization:
                organization = profile.organization
                study = profile.study
                experiment = profile.experiment

                org_teams = DesignTeam.objects.filter(
                    organization=profile.organization)
                for org_team in org_teams:
                    user_profiles = Profile.objects.filter(team=org_team)
                    for user_profile in user_profiles:
                        up_user = user_profile.user
                        user_string = up_user.username + " : " + org_team.name
                        all_users[user_string] = up_user.id
                org_teams_ids = org_teams.values('id')
                session_teams = SessionTeam.objects.filter(
                    team_id__in=org_teams_ids)
                for st in session_teams:
                    st_dict[st.session_id] = DesignTeam.objects.filter(
                        id=st.team_id).first()

                # Note: minus before index means descending order
                current_exercises = Exercise.objects.filter(
                    experiment=experiment).order_by('-id')
                for exercise in current_exercises:
                    exercise_sessions = []
                    sessions = Session.objects.filter(
                        exercise=exercise).order_by('index')
                    all_archived = True
                    session_prev = None
                    for session in sessions:
                        if session_prev:
                            # Keep track of next session for each session
                            session_next[session_prev] = session
                        exercise_sessions.append(session)
                        if session.status != Session.ARCHIVED:
                            # Check if all sessions in exercise are archived
                            all_archived = False
                        session_prev = session
                    # Separate available and archived exercises
                    if all_archived:
                        archived_exercises[exercise] = exercise_sessions
                    else:
                        exercises[exercise] = exercise_sessions

                markets = Market.objects.all()
                structures = Structure.objects.all()

                sorted_all_users = collections.OrderedDict()
                for key, value in sorted(all_users.items()):
                    sorted_all_users[key] = value

            context = {
                'org_teams': org_teams,
                'organization': organization,
                'study': study,
                'experiment': experiment,
                'session_teams': session_teams,
                'st_dict': st_dict,
                'session_next': session_next,
                'markets': markets,
                'structures': structures,
                'all_users': sorted_all_users,
                'exercises': exercises,
                'archived_exercises': archived_exercises
            }
            context['BUST'] = cache_bust()
            response = HttpResponse(render(request, "experiment.html",
                                           context))
            response.set_cookie('username', request.user.username)
    else:
        response = HttpResponse(render(request, "home.html"))
    return response
Exemplo n.º 10
0
def ateams_postsession(request):
    context = {}
    context['BUST'] = cache_bust()
    response = None
    role = None
    st = None
    pos = 0
    team_type = 0
    if request.user.is_authenticated:
        st = SessionTeam.objects.filter(
            Q(session__status__in=Session.ACTIVE_STATES)
            & Q(team=request.user.profile.team)).first()
        if st:
            context = get_cutsom_links(request, st, context)
            if st.session.status == Session.POSTSESSION:
                is_team = True
                # TODO: Make individual/team a property of Structure
                if st.session.structure.name == "Extra":
                    is_team = False
                context['is_team'] = is_team

                num_sessions = Session.objects.filter(
                    exercise=st.session.exercise).count()
                if st.session.index == 1:
                    context['first'] = True
                    if st.session.index != num_sessions:
                        context['last'] = False
                elif st.session.index == num_sessions:
                    context['first'] = False
                    context['last'] = True
                else:
                    context['first'] = False
                    context['last'] = False

                context['session_ai'] = st.session.use_ai

                response = HttpResponse(
                    render(request, "postsession.html", context))
                response.set_cookie('use_ai', st.session.use_ai)
                response.set_cookie('username', request.user.username)
            else:
                if st.session.status == Session.SETUP:
                    context['redir'] = "/setup/"
                elif st.session.status == Session.PRESESSION:
                    context['redir'] = "/presession/"
                elif st.session.status == Session.RUNNING:
                    position = UserPosition.objects.filter(
                        Q(session=st.session)
                        & Q(user=request.user)).first().position
                    if position:
                        if position.role.name == "Business":
                            context['redir'] = "/business/"
                        elif position.role.name == "OpsPlanner":
                            context['redir'] = "/ops/"
                        elif position.role.name == "Designer":
                            context['redir'] = "/design/"
                        elif position.role.name == "Process":
                            context['redir'] = "/process/"
                response = HttpResponse(
                    render(request, "postsession.html", context))
        else:
            context['redir'] = "/"
            response = HttpResponse(
                render(request, "postsession.html", context))
    else:
        response = HttpResponse(render(request, "home.html"))
    return response