Line data Source code
1 : /*! 2 : * \file esys/repo/gitstats/dataperiod.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2022 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/gitstats/dataperiod.h" 20 : 21 : namespace esys::repo::gitstats 22 : { 23 : 24 0 : DataPeriod::DataPeriod() = default; 25 : 26 3 : DataPeriod::DataPeriod(unsigned int period) 27 3 : : m_period(period) 28 : { 29 3 : } 30 : 31 3 : DataPeriod::~DataPeriod() = default; 32 : 33 0 : void DataPeriod::set_period(unsigned int period) 34 : { 35 0 : m_period = period; 36 0 : } 37 : 38 0 : unsigned int DataPeriod::get_period() const 39 : { 40 0 : return m_period; 41 : } 42 : 43 0 : void DataPeriod::set_author_by(AuthorBy author_by) 44 : { 45 0 : m_author_by = author_by; 46 0 : } 47 : 48 7 : DataPeriod::AuthorBy DataPeriod::get_author_by() const 49 : { 50 7 : return m_author_by; 51 : } 52 : 53 4 : std::shared_ptr<DataPeriodAuthor> DataPeriod::get_author(std::shared_ptr<git::Person> author) 54 : { 55 4 : std::string key; 56 : 57 4 : switch (get_author_by()) 58 : { 59 0 : case AuthorBy::NOT_SET: return nullptr; 60 4 : case AuthorBy::EMAIL: key = author->get_email(); break; 61 0 : case AuthorBy::NAME: key = author->get_name(); break; 62 0 : default: return nullptr; 63 : } 64 4 : auto it = m_authors.find(key); 65 4 : if (it == m_authors.end()) return nullptr; 66 5 : return it->second; 67 4 : } 68 : 69 4 : std::shared_ptr<DataPeriodAuthor> DataPeriod::get_author_or_new(std::shared_ptr<git::Person> author) 70 : { 71 8 : auto result = get_author(author); 72 : 73 4 : if (result != nullptr) return result; 74 : 75 3 : std::string key; 76 : 77 3 : switch (get_author_by()) 78 : { 79 0 : case AuthorBy::NOT_SET: return nullptr; 80 3 : case AuthorBy::EMAIL: key = author->get_email(); break; 81 0 : case AuthorBy::NAME: key = author->get_name(); break; 82 0 : default: return nullptr; 83 : } 84 : 85 3 : auto new_data = std::make_shared<DataPeriodAuthor>(author); 86 3 : m_authors[key] = new_data; 87 3 : return new_data; 88 7 : } 89 : 90 6 : std::map<std::string, std::shared_ptr<DataPeriodAuthor>> &DataPeriod::get_period_author_map() 91 : { 92 6 : return m_authors; 93 : } 94 : 95 : } // namespace esys::repo::gitstats