From 63b0d6b180a41547aee9028d200992f53c5a043f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 8 Aug 2018 10:24:09 +0100 Subject: [PATCH] Basic stuff to count successful DCP encodes. --- src/lib/analytics.cc | 87 +++++++++++++++++++++++++++++++++++ src/lib/analytics.h | 40 ++++++++++++++++ src/lib/config.cc | 30 +----------- src/lib/config.h | 7 +-- src/lib/state.cc | 54 ++++++++++++++++++++++ src/lib/state.h | 36 +++++++++++++++ src/lib/transcode_job.cc | 9 +++- src/lib/wscript | 2 + src/tools/dcpomatic_cli.cc | 2 +- src/tools/dcpomatic_create.cc | 2 +- 10 files changed, 232 insertions(+), 37 deletions(-) create mode 100644 src/lib/analytics.cc create mode 100644 src/lib/analytics.h create mode 100644 src/lib/state.cc create mode 100644 src/lib/state.h diff --git a/src/lib/analytics.cc b/src/lib/analytics.cc new file mode 100644 index 000000000..74c21a29c --- /dev/null +++ b/src/lib/analytics.cc @@ -0,0 +1,87 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include "analytics.h" +#include "exceptions.h" +#include +#include +#include +#include +#include + +using std::string; +using dcp::raw_convert; +using boost::algorithm::trim; + +Analytics* Analytics::_instance; +int const Analytics::_current_version = 1; + +Analytics::Analytics () + : _successful_dcp_encodes (0) +{ + +} + +void +Analytics::successful_dcp_encode () +{ + ++_successful_dcp_encodes; + write (); +} + +void +Analytics::write () const +{ + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("Analytics"); + + root->add_child("Version")->add_child_text(raw_convert(_current_version)); + root->add_child("SuccessfulDCPEncodes")->add_child_text(raw_convert(_successful_dcp_encodes)); + + try { + doc.write_to_file_formatted(path("analytics.xml").string()); + } catch (xmlpp::exception& e) { + string s = e.what (); + trim (s); + throw FileError (s, path("analytics.xml")); + } +} + +void +Analytics::read () +try +{ + cxml::Document f ("Analytics"); + f.read_file (path("analytics.xml")); + _successful_dcp_encodes = f.number_child("SuccessfulDCPEncodes"); +} catch (...) { + /* Never mind */ +} + +Analytics* +Analytics::instance () +{ + if (!_instance) { + _instance = new Analytics(); + _instance->read(); + } + + return _instance; +} diff --git a/src/lib/analytics.h b/src/lib/analytics.h new file mode 100644 index 000000000..b439fca8c --- /dev/null +++ b/src/lib/analytics.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include "state.h" + +class Analytics : public State +{ +public: + Analytics (); + + void successful_dcp_encode (); + + void write () const; + void read (); + + static Analytics* instance (); + +private: + int _successful_dcp_encodes; + + static Analytics* _instance; + static int const _current_version; +}; diff --git a/src/lib/config.cc b/src/lib/config.cc index 7e2cdabf6..0b5f7d89a 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -68,7 +68,6 @@ int const Config::_current_version = 3; boost::signals2::signal Config::FailedToLoad; boost::signals2::signal Config::Warning; boost::signals2::signal Config::BadSignerChain; -boost::optional Config::override_path; /** Construct default configuration */ Config::Config () @@ -484,33 +483,6 @@ catch (...) { write (); } -/** @return Filename to write configuration to */ -boost::filesystem::path -Config::path (string file, bool create_directories) -{ - boost::filesystem::path p; - if (override_path) { - p = *override_path; - } else { -#ifdef DCPOMATIC_OSX - p /= g_get_home_dir (); - p /= "Library"; - p /= "Preferences"; - p /= "com.dcpomatic"; - p /= "2"; -#else - p /= g_get_user_config_dir (); - p /= "dcpomatic2"; -#endif - } - boost::system::error_code ec; - if (create_directories) { - boost::filesystem::create_directories (p, ec); - } - p /= file; - return p; -} - /** @return Singleton instance */ Config * Config::instance () @@ -538,7 +510,7 @@ Config::write_config () const xmlpp::Element* root = doc.create_root_node ("Config"); /* [XML] Version The version number of the configuration file format */ - root->add_child("Version")->add_child_text (String::compose ("%1", _current_version)); + root->add_child("Version")->add_child_text (raw_convert(_current_version)); /* [XML] MasterEncodingThreads Number of encoding threads to use when running as master. */ root->add_child("MasterEncodingThreads")->add_child_text (raw_convert (_master_encoding_threads)); /* [XML] ServerEncodingThreads Number of encoding threads to use when running as server. */ diff --git a/src/lib/config.h b/src/lib/config.h index dbe6a9c21..e5a4e5a9f 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -27,6 +27,7 @@ #include "isdcf_metadata.h" #include "types.h" +#include "state.h" #include #include #include @@ -45,7 +46,7 @@ class DKDMGroup; /** @class Config * @brief A singleton class holding configuration. */ -class Config : public boost::noncopyable +class Config : public State { public: /** @return number of threads which a master DoM should use for J2K encoding on the local machine */ @@ -801,12 +802,8 @@ public: static bool have_existing (std::string); static boost::filesystem::path config_file (); - /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml and cinemas.xml */ - static boost::optional override_path; - private: Config (); - static boost::filesystem::path path (std::string file, bool create_directories = true); void read (); void set_defaults (); void set_kdm_email_to_default (); diff --git a/src/lib/state.cc b/src/lib/state.cc new file mode 100644 index 000000000..abb197695 --- /dev/null +++ b/src/lib/state.cc @@ -0,0 +1,54 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include "state.h" +#include + +using std::string; + +boost::optional State::override_path; + +/** @param file State filename + * @return Full path to write @file to */ +boost::filesystem::path +State::path (string file, bool create_directories) +{ + boost::filesystem::path p; + if (override_path) { + p = *override_path; + } else { +#ifdef DCPOMATIC_OSX + p /= g_get_home_dir (); + p /= "Library"; + p /= "Preferences"; + p /= "com.dcpomatic"; + p /= "2"; +#else + p /= g_get_user_config_dir (); + p /= "dcpomatic2"; +#endif + } + boost::system::error_code ec; + if (create_directories) { + boost::filesystem::create_directories (p, ec); + } + p /= file; + return p; +} diff --git a/src/lib/state.h b/src/lib/state.h new file mode 100644 index 000000000..2ba3cf173 --- /dev/null +++ b/src/lib/state.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include +#include +#include + +class State : public boost::noncopyable +{ +public: + virtual void read () = 0; + virtual void write () const = 0; + + /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml, cinemas.xml etc. */ + static boost::optional override_path; + +protected: + static boost::filesystem::path path (std::string file, bool create_directories = true); +}; diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc index 420f5a8d2..23f30991e 100644 --- a/src/lib/transcode_job.cc +++ b/src/lib/transcode_job.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -23,6 +23,7 @@ */ #include "transcode_job.h" +#include "analytics.h" #include "dcp_encoder.h" #include "upload_job.h" #include "job_manager.h" @@ -44,6 +45,7 @@ using std::fixed; using std::setprecision; using std::cout; using boost::shared_ptr; +using boost::dynamic_pointer_cast; /** @param film Film to use */ TranscodeJob::TranscodeJob (shared_ptr film) @@ -92,6 +94,11 @@ TranscodeJob::run () } LOG_GENERAL (N_("Transcode job completed successfully: %1 fps"), fps); + + if (dynamic_pointer_cast(_encoder)) { + Analytics::instance()->successful_dcp_encode(); + } + _encoder.reset (); /* XXX: this shouldn't be here */ diff --git a/src/lib/wscript b/src/lib/wscript index 68e44ccd0..069477de9 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -23,6 +23,7 @@ import i18n sources = """ active_text.cc analyse_audio_job.cc + analytics.cc atmos_mxf_content.cc audio_analysis.cc audio_buffers.cc @@ -134,6 +135,7 @@ sources = """ send_problem_report_job.cc server.cc shuffler.cc + state.cc string_log_entry.cc string_text_file.cc string_text_file_content.cc diff --git a/src/tools/dcpomatic_cli.cc b/src/tools/dcpomatic_cli.cc index 7fc5ed55d..43a4f8319 100644 --- a/src/tools/dcpomatic_cli.cc +++ b/src/tools/dcpomatic_cli.cc @@ -269,7 +269,7 @@ main (int argc, char* argv[]) } if (config) { - Config::override_path = *config; + State::override_path = *config; } if (servers) { diff --git a/src/tools/dcpomatic_create.cc b/src/tools/dcpomatic_create.cc index 5c6fc3567..4ae8aee05 100644 --- a/src/tools/dcpomatic_create.cc +++ b/src/tools/dcpomatic_create.cc @@ -210,7 +210,7 @@ main (int argc, char* argv[]) } if (config) { - Config::override_path = *config; + State::override_path = *config; } if (!content_ratio) { -- 2.30.2