TaskStats: remove unused attribute "Time"
[xcsoar.git] / test / src / FlightPhaseJSON.cpp
bloba7802bf282b050474ccee52381b71d3dcb4f9c2c
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "FlightPhaseJSON.hpp"
24 #include "Formatter/TimeFormatter.hpp"
25 #include "Util/StaticString.hpp"
26 #include "JSON/Writer.hpp"
27 #include "JSON/GeoWriter.hpp"
29 static const char *
30 FormatPhaseType(Phase::Type phase_type)
32 switch (phase_type) {
33 case Phase::Type::CRUISE:
34 return "cruise";
35 case Phase::Type::CIRCLING:
36 return "circling";
37 case Phase::Type::POWERED:
38 return "powered";
39 default:
40 return "";
44 static const char *
45 FormatCirclingDirection(Phase::CirclingDirection circling_direction)
47 switch (circling_direction) {
48 case Phase::CirclingDirection::LEFT:
49 return "left";
50 case Phase::CirclingDirection::RIGHT:
51 return "right";
52 case Phase::CirclingDirection::MIXED:
53 return "mixed";
54 default:
55 return "";
59 static void
60 WritePhase(TextWriter &writer, Phase &phase)
62 JSON::ObjectWriter object(writer);
63 NarrowString<64> buffer;
65 FormatISO8601(buffer.buffer(), phase.start_datetime);
66 object.WriteElement("start_time", JSON::WriteString, buffer);
68 FormatISO8601(buffer.buffer(), phase.end_datetime);
69 object.WriteElement("end_time", JSON::WriteString, buffer);
71 object.WriteElement("type", JSON::WriteString,
72 FormatPhaseType(phase.phase_type));
73 object.WriteElement("duration", JSON::WriteInteger, (int)phase.duration);
74 object.WriteElement("circling_direction", JSON::WriteString,
75 FormatCirclingDirection(phase.circling_direction));
76 object.WriteElement("alt_diff", JSON::WriteInteger, (int)phase.alt_diff);
77 object.WriteElement("distance", JSON::WriteInteger, (int)phase.distance);
78 object.WriteElement("speed", JSON::WriteFixed, phase.GetSpeed());
79 object.WriteElement("vario", JSON::WriteFixed, phase.GetVario());
80 object.WriteElement("glide_rate", JSON::WriteFixed, phase.GetGlideRate());
83 static void
84 WriteCirclingStats(TextWriter &writer, const Phase &stats)
86 JSON::ObjectWriter object(writer);
87 object.WriteElement("alt_diff", JSON::WriteInteger, (int)stats.alt_diff);
88 object.WriteElement("duration", JSON::WriteInteger, (int)stats.duration);
89 object.WriteElement("fraction", JSON::WriteFixed, stats.fraction);
90 object.WriteElement("vario", JSON::WriteFixed, stats.GetVario());
91 object.WriteElement("count", JSON::WriteInteger, stats.merges);
94 static void
95 WriteCruiseStats(TextWriter &writer, const Phase &stats)
97 JSON::ObjectWriter object(writer);
98 object.WriteElement("alt_diff", JSON::WriteInteger, (int)stats.alt_diff);
99 object.WriteElement("duration", JSON::WriteInteger, (int)stats.duration);
100 object.WriteElement("fraction", JSON::WriteFixed, stats.fraction);
101 object.WriteElement("distance", JSON::WriteInteger, (int)stats.distance);
102 object.WriteElement("speed", JSON::WriteFixed, stats.GetSpeed());
103 object.WriteElement("vario", JSON::WriteFixed, stats.GetVario());
104 object.WriteElement("glide_rate", JSON::WriteFixed, stats.GetGlideRate());
105 object.WriteElement("count", JSON::WriteInteger, stats.merges);
108 void
109 WritePerformanceStats(TextWriter &writer, const PhaseTotals &totals)
111 JSON::ObjectWriter object(writer);
112 object.WriteElement("circling_total", WriteCirclingStats,
113 totals.total_circstats);
114 object.WriteElement("circling_left", WriteCirclingStats,
115 totals.left_circstats);
116 object.WriteElement("circling_right", WriteCirclingStats,
117 totals.right_circstats);
118 object.WriteElement("circling_mixed", WriteCirclingStats,
119 totals.mixed_circstats);
120 object.WriteElement("cruise_total", WriteCruiseStats,
121 totals.total_cruisestats);
124 void
125 WritePhaseList(TextWriter &writer, const PhaseList &phases)
127 JSON::ArrayWriter array(writer);
128 for (Phase phase : phases) {
129 array.WriteElement(WritePhase, phase);