Skip to content

Commit

Permalink
add "export to csv" menu option.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlawson committed Jul 4, 2004
1 parent 4c4cda3 commit f92c45a
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 18 deletions.
16 changes: 8 additions & 8 deletions changes.txt
@@ -1,10 +1,10 @@
Changes in version 1.3.0 (released 04-jul-2004)

now supports ogr-p2 logs
winxp themes
displays year in all timestamps
has improved year guessing algorithm based on the last-modified timestamp of the log file (since the year is not saved by the client in log files)
fixes some thread-safety crash issues
displays the hourglass when it is busy loading or redrawing
greys out the projects in the View menu if no data is available.

- now supports ogr-p2 logs
- winxp themes
- displays year in all timestamps
- has improved year guessing algorithm based on the last-modified timestamp of the log file (since the year is not saved by the client in log files)
- fixes some thread-safety crash issues
- displays the hourglass when it is busy loading or redrawing
- greys out the projects in the View menu if no data is available.
- added "export to cvs" menu option.
40 changes: 38 additions & 2 deletions guigraph.cpp
Expand Up @@ -5,7 +5,7 @@
#include "guiwin.h"

#if (!defined(lint) && defined(__showids__))
static char *id="@(#)$Id: guigraph.cpp,v 1.16 2004/07/04 20:49:40 jlawson Exp $";
static char *id="@(#)$Id: guigraph.cpp,v 1.17 2004/07/04 20:50:58 jlawson Exp $";
#endif


Expand Down Expand Up @@ -766,7 +766,7 @@ int MyGraphWindow::DoRedraw(HDC dc, RECT clientrect)
// start drawing the points
HPEN graphline = CreatePen(PS_SOLID, 2, RGB(0x99, 0x33, 0x33));
HPEN oldpen = (HPEN) SelectObject(dc, graphline);
for (LogDataStorage_t::iterator pointiter = logdata.begin();
for (LogDataStorage_t::const_iterator pointiter = logdata.begin();
pointiter != logdata.end(); pointiter++) {
paintstr.DrawToDataPoint(*pointiter);
}
Expand Down Expand Up @@ -799,6 +799,42 @@ int MyGraphWindow::DoRedraw(HDC dc, RECT clientrect)
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

// Returns 0 on success, otherwise error.

int MyGraphWindow::ExportCSV(const char *outputfile)
{
int retval = 0;
EnterCriticalSection(&loggerbusy);

FILE *fp = fopen(outputfile, "wt");
if (fp != NULL) {
fprintf(fp, "timestamp,rate,duration,statunits\n");

for (LogDataStorage_t::const_iterator pointiter = logdata.begin();
pointiter != logdata.end(); pointiter++)
{
char buffer[30];
struct tm *gmt = gmtime(&pointiter->timestamp);
if (gmt)
strftime(buffer, sizeof(buffer), "%Y/%m/%d %H:%M:%S", gmt);
else
strcpy(buffer, "unknown");

fprintf(fp, "%s,%g,%g,%g\n", buffer, pointiter->rate, pointiter->duration, pointiter->statunits);
}
fclose(fp);
} else {
retval = -1;
}

LeaveCriticalSection(&loggerbusy);
return retval;
}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

UINT MyGraphWindow::GetViewedContestMenuId(void) const
{
switch (viewedcontest) {
Expand Down
5 changes: 5 additions & 0 deletions guiwin.h
Expand Up @@ -58,6 +58,7 @@ extern const char *LogGetCurrentLogFilename(void);
extern void LogSetCurrentLogFilename(const char *filename, bool removeQuotes);
extern LRESULT CALLBACK Main_WindowProc(HWND,UINT,WPARAM,LPARAM);
extern void Main_CmOpenLogfile(HWND hwnd);
extern void Main_CmExportCSV(HWND hwnd);
extern void Main_CmAbout(HWND hwnd);
extern void Main_UpdateTitlebar(HWND hwnd);

Expand Down Expand Up @@ -176,8 +177,12 @@ class MyGraphWindow
LoggerState GetStatusValue(void) const { return loggerstate; }

// public interface methods.
// indicates of GetStatusString() will return a different value.
bool HasStatusChanged(void) const { return bStateChanged; }

// public interface methods.
int ExportCSV(const char *outputfile);

// public interface methods.
UINT GetViewedContestMenuId(void) const;
bool SetViewedContestByMenuId(UINT menuid);
Expand Down
2 changes: 2 additions & 0 deletions guiwin.rc
Expand Up @@ -82,6 +82,8 @@ BEGIN
MENUITEM "&Open log file...", IDM_OPENLOGFILE
MENUITEM "&Refresh log file", IDM_REFRESHLOGFILE
MENUITEM SEPARATOR
MENUITEM "Export to CSV...", 40003
MENUITEM SEPARATOR
MENUITEM "E&xit", IDM_EXIT
END
POPUP "&View"
Expand Down
35 changes: 34 additions & 1 deletion guiwind.cpp
Expand Up @@ -6,7 +6,7 @@


#if (!defined(lint) && defined(__showids__))
static char *id="@(#)$Id: guiwind.cpp,v 1.18 2004/07/04 11:46:15 jlawson Exp $";
static char *id="@(#)$Id: guiwind.cpp,v 1.19 2004/07/04 20:50:58 jlawson Exp $";
#endif


Expand Down Expand Up @@ -102,6 +102,7 @@ LRESULT CALLBACK Main_WindowProc(
EnableMenuItem(hPopup, IDM_CONTEST_OGR, MF_BYCOMMAND | (graphwin.IsDataAvailable(MyGraphWindow::CONTEST_OGR) ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hPopup, IDM_CONTEST_OGR_P2, MF_BYCOMMAND | (graphwin.IsDataAvailable(MyGraphWindow::CONTEST_OGR_P2) ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hPopup, IDM_SHOWIDLE, MF_BYCOMMAND | dwEnabledWithLogAndData);
EnableMenuItem(hPopup, IDM_EXPORT_CSV, MF_BYCOMMAND | dwEnabledWithLogAndData);

// Enable the "full zoom" menu item only when there is data and zoomed in.
time_t zoomleft, zoomright;
Expand Down Expand Up @@ -187,6 +188,11 @@ LRESULT CALLBACK Main_WindowProc(
graphwin.LogRereadNeeded(hwnd);
return FALSE;
}
else if (wID == IDM_EXPORT_CSV)
{
Main_CmExportCSV(hwnd);
return FALSE;
}
else if (wID == IDM_GRAPHCONFIG)
{
// require that a logfile is already loaded.
Expand Down Expand Up @@ -287,6 +293,33 @@ void Main_CmOpenLogfile(HWND hwnd)
}
}

void Main_CmExportCSV(HWND hwnd)
{
OPENFILENAME ofn;
char filterarray[] = { "CSV (Comma delimited) (*.CSV)\0" "*.CSV\0"
"All files (*.*)\0" "*.*\0" "\0\0" };

char exportfilename[512] = { '\0' };

memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = filterarray;
ofn.lpstrFile = exportfilename;
ofn.nMaxFile = sizeof(exportfilename);
ofn.lpstrTitle = "Select new file to export to";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrDefExt = "CSV";

if (GetSaveFileName(&ofn))
{
int retval = graphwin.ExportCSV(exportfilename);
if (retval != 0) {
MessageBox(hwnd, "Failed to write exported data to file.",
NULL, MB_ICONERROR | MB_OK);
}
}
}

void Main_UpdateTitlebar(HWND hwnd)
{
Expand Down
7 changes: 4 additions & 3 deletions resource.h
@@ -1,5 +1,5 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Microsoft Visual C++ generated include file.
// Used by guiwin.rc
//
#define VERSIONINFO_1 1
Expand All @@ -25,14 +25,15 @@
#define IDS_ENDDATE 526
#define IDS_STARTDATE 527
#define IDC_STATUSBAR 600
#define IDM_EXPORT_CSV 40003
#define IDC_STATIC -1

// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_COMMAND_VALUE 40004
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
Expand Down
4 changes: 0 additions & 4 deletions todo.txt
Expand Up @@ -8,10 +8,6 @@ shared with all others.
- allow simultaneously displaying multiple projects at the same time
using colors and labels to indicate projects.

- add "export" function to dump parsed dates and keyrates into a
comma-separated text file that could be imported into Excel or some other
application.

- add parsing of personal proxy log files.

- localtime timestamp display
Expand Down

0 comments on commit f92c45a

Please sign in to comment.