1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008, 2011-2013, 2015-2018 - TortoiseGit
4 // Copyright (C) 2003-2011, 2015 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "StandAloneDlg.h"
25 #include "UnicodeUtils.h"
28 #include "GitLogListBase.h"
31 * \ingroup TortoiseProc
32 * Helper class for drawing and then saving the drawing to a meta file (wmf)
34 class CMyMetaFileDC
: public CMetaFileDC
37 HGDIOBJ
SelectObject(HGDIOBJ hObject
)
39 return (hObject
!= nullptr) ? ::SelectObject(m_hDC
, hObject
) : nullptr;
44 * \ingroup TortoiseProc
45 * Helper dialog showing statistics gathered from the log messages shown in the
48 * The function GatherData() collects statistical information and stores it
49 * in the corresponding member variables. You can access the data as shown in
50 * the following examples:
52 * commits = m_commitsPerWeekAndAuthor[week_nr][author_name];
53 * filechanges = m_filechangesPerWeekAndAuthor[week_nr][author_name];
54 * commits = m_commitsPerAuthor[author_name];
57 class CStatGraphDlg
: public CResizableStandAloneDialog
//CResizableStandAloneDialog
59 DECLARE_DYNAMIC(CStatGraphDlg
)
62 CStatGraphDlg(CWnd
* pParent
= nullptr);
63 virtual ~CStatGraphDlg();
65 enum { IDD
= IDD_STATGRAPH
};
67 std::vector
<GitRevLoglist
*> m_ShowList
;
69 // Data passed from the caller of the dialog.
70 CDWordArray m_parDates
;
71 CDWordArray m_parFileChanges
;
72 CDWordArray m_parFileChanges2
;
73 CDWordArray m_lineInc
;
74 CDWordArray m_lineInc2
;
75 CDWordArray m_lineDec
;
76 CDWordArray m_lineDec2
;
77 CDWordArray m_lineNew
;
78 CDWordArray m_lineNew2
;
79 CDWordArray m_lineDel
;
80 CDWordArray m_lineDel2
;
82 CStringArray m_parAuthors
;
88 static const long int m_SecondsInWeek
= 604800; // ... a week has 604800 seconds
89 static const long int m_SecondsInDay
= 86400; // ... a day has 86400.0 seconds
90 static const int m_CoeffAuthorShip
= 2;
94 /// The types of units used in the various graphs.
104 // Available next metrics
111 PercentageOfAuthorship
,
119 //TODO: try substitute map to hash_map
120 /// The mapping type used to store data per interval/week and author.
121 typedef std::map
<int, std::map
<tstring
, LONG
> > IntervalDataMap
;
123 //TODO: try substitute few Maps to one map, that store needs informations about Authors
124 /// The mapping type used to store data per author.
125 typedef std::map
<tstring
, LONG
> AuthorDataMap
;
126 /// The mapping type used to store data per Percentage Of Authorship
127 typedef std::map
<tstring
, double> AuthorshipDataMap
;
129 // *** Re-implemented member functions from CDialog
130 virtual void OnOK() override
;
131 virtual void OnCancel() override
;
133 virtual void DoDataExchange(CDataExchange
* pDX
) override
;
134 virtual BOOL
OnInitDialog() override
;
135 void ShowLabels(BOOL bShow
);
136 afx_msg
void OnCbnSelchangeGraphcombo();
137 afx_msg
void OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
);
138 afx_msg
void OnNeedText(NMHDR
*pnmh
, LRESULT
*pResult
);
139 afx_msg
void OnBnClickedGraphbarbutton();
140 afx_msg
void OnBnClickedGraphbarstackedbutton();
141 afx_msg
void OnBnClickedGraphlinebutton();
142 afx_msg
void OnBnClickedGraphlinestackedbutton();
143 afx_msg
void OnBnClickedGraphpiebutton();
144 afx_msg
void OnFileSavestatgraphas();
145 afx_msg
void OnBnClickedFetchDiff();
146 afx_msg
void OnBnClickedCommitternames();
147 afx_msg
void OnBnClickedCommitdates();
148 DECLARE_MESSAGE_MAP()
150 // ** Member functions **
152 /// Updates the variables m_nWeeks, m_nDays and m_minDate
153 void UpdateWeekCount();
154 /// Returns the week-of-the-year for the given time.
155 int GetCalendarWeek(const CTime
& time
);
156 /// Parses the data given to the dialog and generates mappings with statistical data.
157 int GatherData(BOOL fetchdiff
= FALSE
, BOOL keepFetchedData
= FALSE
);
158 /// Populates the lists passed as arguments based on the commit threshold set with the skipper.
159 void FilterSkippedAuthors(std::list
<tstring
>& included_authors
, std::list
<tstring
>& skipped_authors
);
160 /// Shows the graph Percentage Of Authorship
161 void ShowPercentageOfAuthorship();
162 /// Shows the graph with commit counts per author.
163 void ShowCommitsByAuthor();
164 /// Shows the graph with commit counts per author and date.
165 void ShowByDate(int StringY
, int title
, IntervalDataMap
&data
);
166 /// Shows the initial statistics page.
169 /// Rolling Percentage Of Authorship of author to integer
170 int RollPercentageOfAuthorship(double it
);
172 /// Load list of drawing authors
173 template <class MAP
> void LoadListOfAuthors (MAP
&map
, bool reloadSkiper
= false, bool compare
= false);
175 // If we have other authors, count them and their commits.
177 void DrawOthers(const std::list
<tstring
> &others
, MyGraphSeries
*graphData
, MAP
&map
);
180 /// Called when user checks/unchecks the "Authors case sensitive" checkbox.
181 /// Recalculates statistical data because the number and names of authors
182 /// can have changed. Also calls RedrawGraph().
183 void AuthorsCaseSensitiveChanged();
184 /// Called when user checks/unchecks the "Sort by commit count" checkbox.
185 /// Calls RedrawGraph().
186 void SortModeChanged();
187 /// Clears the current graph and frees all data series.
189 /// Updates the currently shown statistics page.
192 /// PreShow Statistic function
193 bool PreViewStat(bool fShowLabels
);
194 /// PreShow Graphic function
195 MyGraphSeries
* PreViewGraph(__in UINT GraphTitle
, __in UINT YAxisLabel
, __in UINT XAxisLabel
= NULL
);
196 /// Show Selected Static metric
197 void ShowSelectStat(Metrics SelectedMetric
, bool reloadSkiper
= false);
199 int GetUnit(const CTime
& time
);
200 CStatGraphDlg::UnitType
GetUnitType();
201 CString
GetUnitString();
202 CString
GetUnitLabel(int unit
, CTime
&lasttime
);
204 void EnableDisableMenu();
206 void SaveGraph(CString sFilename
);
207 int GetEncoderClsid(const WCHAR
* format
, CLSID
* pClsid
);
209 void StoreCurrentGraphType();
210 void ShowErrorMessage();
212 // init ruler & limit its range
213 void SetSkipper (bool reloadSkiper
);
215 //Load statistical queries
216 void LoadStatQueries(__in UINT curStr
, Metrics loadMetric
, bool setDef
= false);
218 //Considers coefficient contribution author
219 double CoeffContribution(int distFromEnd
);
221 CPtrArray m_graphDataArray
;
223 CComboBox m_cGraphType
;
224 CSliderCtrl m_Skipper
;
225 BOOL m_bAuthorsCaseSensitive
;
226 BOOL m_bSortByCommitCount
;
227 BOOL m_bUseCommitterNames
;
228 BOOL m_bUseCommitDates
;
231 CMFCButton m_btnGraphBar
;
232 CMFCButton m_btnGraphBarStacked
;
233 CMFCButton m_btnGraphLine
;
234 CMFCButton m_btnGraphLineStacked
;
235 CMFCButton m_btnGraphPie
;
237 MyGraph::GraphType m_GraphType
;
242 // ** Member variables holding the statistical data **
244 /// Number of days in the revision interval.
246 /// Number of weeks in the revision interval.
248 /// The starting date/time for the revision interval.
249 __time64_t m_minDate
;
250 /// The ending date/time for the revision interval.
251 __time64_t m_maxDate
;
252 /// The total number of commits (equals size of the m_parXXX arrays).
253 INT_PTR m_nTotalCommits
;
254 /// The total number of file changes.
255 LONG m_nTotalFileChanges
;
256 /// Holds the number of commits per unit and author.
257 IntervalDataMap m_commitsPerUnitAndAuthor
;
259 IntervalDataMap m_LinesWPerUnitAndAuthor
;
260 IntervalDataMap m_LinesWOPerUnitAndAuthor
;
262 /// Holds the number of file changes per unit and author.
263 IntervalDataMap m_filechangesPerUnitAndAuthor
;
264 /// First interval number (key) in the mappings.
266 /// Last interval number (key) in the mappings.
268 /// Mapping of total commits per author, access data via
269 AuthorDataMap m_commitsPerAuthor
;
270 /// Mapping of Percentage Of Authorship per author
271 AuthorshipDataMap m_PercentageOfAuthorship
;
273 LONG m_nTotalLinesInc
;
274 LONG m_nTotalLinesDec
;
275 LONG m_nTotalLinesNew
;
276 LONG m_nTotalLinesDel
;
278 /// The list of author names sorted based on commit count
279 /// (author with most commits is first in list).
280 std::list
<tstring
> m_authorNames
;
281 /// unit names by week/month/quarter
282 std::map
<LONG
, tstring
> m_unitNames
;