<commit_before>package hu.sch.web.kp.user;

import hu.sch.domain.user.User;
import hu.sch.domain.*;
import hu.sch.services.ValuationManagerLocal;
import hu.sch.web.kp.KorokPage;
import hu.sch.web.kp.group.GroupHierarchy;
import hu.sch.web.profile.show.ShowPersonPage;
import hu.sch.web.wicket.components.tables.ValuationTableForUser;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author <NAME>
 * @author messo
 */
public class UserHistory extends KorokPage {

    private static final Logger logger = LoggerFactory.getLogger(UserHistory.class);
    private Long id;
    private Long selectedGroupId = null;
    private final String EVERY_GROUP = "Összes kör";
    // DropDownChoiceban használjuk
    protected String selected_text = EVERY_GROUP;
    private boolean own_profile = false;
    @Inject
    private ValuationManagerLocal valuationManager;

    public UserHistory() {
        own_profile = true;
        initComponents();
    }

    public UserHistory(PageParameters parameters) {
        try {
            id = parameters.get("id").toLong();
            selectedGroupId = parameters.get("group").toLong(0l);
            if (selectedGroupId != 0l) {
                Group g = groupManager.findGroupById(selectedGroupId);
                if (g != null) {
                    selected_text = g.getName();
                } else {
                    logger.warn("Group not found with id: {}", id);
                    selected_text = "NOT FOUND";
                }
            } else {
                selectedGroupId = null;
            }
        } catch (Throwable t) {
            logger.warn("Error while loading parameters.", t);
        }
        initComponents();
    }

    private void initComponents() {
        User user;
        if (id == null) {
            id = getSession().getUserId();
        }
        user = userManager.findUserById(id, true);
        if (user == null) {
            logger.warn("Not founded user for UserHistory page with id: " + id);
            error("A megadott felhasználóhoz nem tartozik közösségi történet!");
            throw new RestartResponseException(GroupHierarchy.class);
        }

        setHeaderLabelText(user.getFullName() + " közösségi története");
        setTitleText(user.getFullName() + " közösségi története");
        if (own_profile) {
            add(new BookmarkablePageLink<ShowUser>("simpleView", ShowUser.class));
        } else {
            add(new BookmarkablePageLink<ShowUser>("simpleView", ShowUser.class, new PageParameters().add("id", user.getId())));
        }
        add(new BookmarkablePageLink("profilelink", ShowPersonPage.class,
                new PageParameters().add("virid", id.toString())));
        setDefaultModel(new CompoundPropertyModel<User>(user));

        final List<String> groups = new ArrayList<String>();
        groups.add(EVERY_GROUP);

        List<Membership> ms = user.getMemberships();
        for (Membership csoporttagsag : ms) {
            groups.add(csoporttagsag.getGroup().getName());
        }

        DropDownChoice<String> ddc = new DropDownChoice<String>("group", new PropertyModel<String>(this, "selected_text"), groups) {

            @Override
            protected boolean wantOnSelectionChangedNotifications() {
                return true;
            }

            @Override
            protected void onSelectionChanged(final String newSelection) {
                PageParameters pp = new PageParameters();

                // Ez van a legördülő menüben kiválasztva
                String Lselected = groups.get(Integer.valueOf(this.getInput()));

                if (Lselected.equals(EVERY_GROUP)) {
                    // minden kört megjelenítek
                } else {
                    // csak a kiválasztott kört jelenítem meg
                    Group group = groupManager.findGroupByName(Lselected);
                    pp.add("group", group.getId().toString());
                }

                pp.add("id", String.valueOf(id));
                setResponsePage(UserHistory.class, pp);
            }
        };

        add(ddc);

        List<SemesterPoint> semesterPoints = new ArrayList<SemesterPoint>();
        for (Semester s : userManager.getAllValuatedSemesterForUser(user)) {
            semesterPoints.add(new SemesterPoint(s, userManager.getSemesterPointForUser(user, s)));
        }

        // megjelenítés...
        ListView<SemesterPoint> splv = new ListView<SemesterPoint>("semesterPointList", semesterPoints) {

            @Override
            protected void populateItem(ListItem<SemesterPoint> item) {
                SemesterPoint p = item.getModelObject();
                item.add(new Label("semesterPoint.semester", p.getSemester().toString()));
                item.add(new Label("semesterPoint.point", String.valueOf(p.getPoint())));
            }
        };
        add(splv);

        List<ValuationData> list = valuationManager.findRequestsForUser(user, selectedGroupId);

        add(new ValuationTableForUser("table", list).getDataTable());
    }
}

class SemesterPoint implements Serializable {

    private Semester semester;
    private Integer point;

    public SemesterPoint(Semester semester, Integer point) {
        this.semester = semester;
        this.point = point;
    }

    public Semester getSemester() {
        return semester;
    }

    public Integer getPoint() {
        return point;
    }
}
<commit_msg>Fixed valuated semesters in UserHistory #6<commit_after>package hu.sch.web.kp.user;

import hu.sch.domain.user.User;
import hu.sch.domain.*;
import hu.sch.services.ValuationManagerLocal;
import hu.sch.web.kp.KorokPage;
import hu.sch.web.kp.group.GroupHierarchy;
import hu.sch.web.profile.show.ShowPersonPage;
import hu.sch.web.wicket.components.tables.ValuationTableForUser;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author <NAME>
 * @author messo
 */
public class UserHistory extends KorokPage {

    private static final Logger logger = LoggerFactory.getLogger(UserHistory.class);
    private Long id;
    private Long selectedGroupId = null;
    private final String EVERY_GROUP = "Összes kör";
    // DropDownChoiceban használjuk
    protected String selected_text = EVERY_GROUP;
    private boolean own_profile = false;
    @Inject
    private ValuationManagerLocal valuationManager;

    public UserHistory() {
        own_profile = true;
        initComponents();
    }

    public UserHistory(PageParameters parameters) {
        try {
            id = parameters.get("id").toLong();
            selectedGroupId = parameters.get("group").toLong(0l);
            if (selectedGroupId != 0l) {
                Group g = groupManager.findGroupById(selectedGroupId);
                if (g != null) {
                    selected_text = g.getName();
                } else {
                    logger.warn("Group not found with id: {}", id);
                    selected_text = "NOT FOUND";
                }
            } else {
                selectedGroupId = null;
            }
        } catch (Throwable t) {
            logger.warn("Error while loading parameters.", t);
        }
        initComponents();
    }

    private void initComponents() {
        User user;
        if (id == null) {
            id = getSession().getUserId();
        }
        user = userManager.findUserById(id, true);
        if (user == null) {
            logger.warn("Not founded user for UserHistory page with id: " + id);
            error("A megadott felhasználóhoz nem tartozik közösségi történet!");
            throw new RestartResponseException(GroupHierarchy.class);
        }

        setHeaderLabelText(user.getFullName() + " közösségi története");
        setTitleText(user.getFullName() + " közösségi története");
        if (own_profile) {
            add(new BookmarkablePageLink<ShowUser>("simpleView", ShowUser.class));
        } else {
            add(new BookmarkablePageLink<ShowUser>("simpleView", ShowUser.class, new PageParameters().add("id", user.getId())));
        }
        add(new BookmarkablePageLink("profilelink", ShowPersonPage.class,
                new PageParameters().add("virid", id.toString())));
        setDefaultModel(new CompoundPropertyModel<User>(user));

        final List<String> groups = new ArrayList<String>();
        groups.add(EVERY_GROUP);

        List<Membership> ms = user.getMemberships();
        for (Membership csoporttagsag : ms) {
            groups.add(csoporttagsag.getGroup().getName());
        }

        DropDownChoice<String> ddc = new DropDownChoice<String>("group", new PropertyModel<String>(this, "selected_text"), groups) {

            @Override
            protected boolean wantOnSelectionChangedNotifications() {
                return true;
            }

            @Override
            protected void onSelectionChanged(final String newSelection) {
                PageParameters pp = new PageParameters();

                // Ez van a legördülő menüben kiválasztva
                String Lselected = groups.get(Integer.valueOf(this.getInput()));

                if (Lselected.equals(EVERY_GROUP)) {
                    // minden kört megjelenítek
                } else {
                    // csak a kiválasztott kört jelenítem meg
                    Group group = groupManager.findGroupByName(Lselected);
                    pp.add("group", group.getId().toString());
                }

                pp.add("id", String.valueOf(id));
                setResponsePage(UserHistory.class, pp);
            }
        };

        add(ddc);

        List<SemesterPoint> semesterPoints = new ArrayList<SemesterPoint>();
        Semester prev = null;
        for (Semester s : userManager.getAllValuatedSemesterForUser(user)) {
            //Ha van olyan éve, ami előtt és után már kapott közösségi pontot,
            //de abban az évben nem, akkor hozzáadja azt az évet is nulla ponttal
            if(prev != null){
                while(!prev.getPrevious().equals(s)){
                    prev = prev.getPrevious();
                    semesterPoints.add(new SemesterPoint(prev, 0));
                }
            }
            prev = s;
            semesterPoints.add(new SemesterPoint(s, userManager.getSemesterPointForUser(user, s)));
        }

        // megjelenítés...
        ListView<SemesterPoint> splv = new ListView<SemesterPoint>("semesterPointList", semesterPoints) {

            @Override
            protected void populateItem(ListItem<SemesterPoint> item) {
                SemesterPoint p = item.getModelObject();
                item.add(new Label("semesterPoint.semester", p.getSemester().toString()));
                item.add(new Label("semesterPoint.point", String.valueOf(p.getPoint())));
            }
        };
        add(splv);

        List<ValuationData> list = valuationManager.findRequestsForUser(user, selectedGroupId);

        add(new ValuationTableForUser("table", list).getDataTable());
    }
}

class SemesterPoint implements Serializable {

    private Semester semester;
    private Integer point;

    public SemesterPoint(Semester semester, Integer point) {
        this.semester = semester;
        this.point = point;
    }

    public Semester getSemester() {
        return semester;
    }

    public Integer getPoint() {
        return point;
    }
}

{'fraction_non_alphanumeric': 0.10670172922145191, 'fraction_numerical': 0.000796876245119133, 'mean_word_length': 2.4010840108401084, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '676720', 'n_tokens_mistral': 3579, 'n_tokens_neox': 3461, 'n_words': 709}