map(
            flattened_email_logs,
            function (sub) {
              return {
               ...sub,
                server_time: new Date(sub["server_time"]).toUTCString(),
              };
            }
          );

          if (time_corrected_email_logs.length > 0) {
            //check if there is actually any content to be writing

            const json2csv_parser = new Parser();

            const csv = json2csv_parser.parse(time_corrected_email_logs, {
              fields: column_names,
            });

            csv_strings[template_name] = csv;
          }
        }
      });
    })
   .catch((err) => {
      console.log(err);
    })
   .finally(() => {
      mongoose.connection.close();
      return csv_strings;
    });

  return csv_strings;
}

export async function get_csv_strings() {
  const csv_strings = await extractor();
  return { csv_strings };
}

export async function write_csvs() {
  const csv_strings = await extractor();

  const output_dir = `data_extracts/${new Date().toISOString()}`;
  fs.mkdirSync(output_dir, { recursive: true });

  _.forEach(csv_strings, (csv, template_name) => {
    const file_name = `${output_dir}/${template_name}.csv`;
    fs.writeFile(file_name, csv, function (err) {
      console.log(err || `Successfully saved ${file_name}.`);
    });
  });
}
#ifndef SETBOOL_RESPONSE_DCPS_IMPL_H_
#define SETBOOL_RESPONSE_DCPS_IMPL_H_

#include "ccpp.h"
#include "ccpp_SetBool_Response_.h"
#include "TypeSupportMetaHolder.h"
#include "TypeSupport.h"
#include "FooDataWriter_impl.h"
#include "FooDataReader_impl.h"
#include "FooDataReaderView_impl.h"
#include "std_srvs/msg/rosidl_typesupport_opensplice_cpp__visibility_control.h"

namespace std_srvs {

    namespace srv {

        namespace dds_ {

            class ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_std_srvs SetBool_Response_TypeSupportMetaHolder : public ::DDS::OpenSplice::TypeSupportMetaHolder
            {
            public:
                SetBool_Response_TypeSupportMetaHolder ();
                virtual ~SetBool_Response_TypeSupportMetaHolder ();
            
            private:
                ::DDS::OpenSplice::TypeSupportMetaHolder * clone();
            
                ::DDS::OpenSplice::DataWriter * create_datawriter ();
            
                ::DDS::OpenSplice::DataReader * create_datareader ();
            
                ::DDS::OpenSplice::DataReaderView * create_view ();
            };
            
            class ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_std_srvs SetBool_Response_TypeSupport : public virtual SetBool_Response_TypeSupportInterface,
                                                               public ::DDS::OpenSplice::TypeSupport
            {
            public:
                SetBool_Response_TypeSupport ();
            
                virtual ~SetBool_Response_TypeSupport ();
            
            private:
                SetBool_Response_TypeSupport (const SetBool_Response_TypeSupport &);
            
                SetBool_Response_TypeSupport & operator= (const SetBool_Response_TypeSupport &);
            };
            
            typedef SetBool_Response_TypeSupportInterface_var SetBool_Response_TypeSupport_var;
            typedef SetBool_Response_TypeSupportInterface_ptr SetBool_Response_TypeSupport_ptr;
            
            class ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_std_srvs SetBool_Response_DataWriter_impl : public virtual SetBool_Response_DataWriter,
                                                                   public ::DDS::OpenSplice::FooDataWriter_impl
            {
                friend class DDS::OpenSplice::Publisher;
                friend class SetBool_Response_TypeSupportMetaHolder;
            
            public:
                virtual ::DDS::InstanceHandle_t register_instance (
                    const SetBool_Response_ & instance_data) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::InstanceHandle_t register_instance_w_timestamp (
                    const SetBool_Response_ & instance_data,
                    const ::DDS::Time_t & source_timestamp) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::ReturnCode_t unregister_instance (
                    const SetBool_Response_ & instance_data,
                    ::DDS::InstanceHandle_t handle) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::ReturnCode_t unregister_instance_w_timestamp (
                    const SetBool_Response_ & instance_data,
                    ::DDS::InstanceHandle_t handle,
                    const ::DDS::Time_t & source_timestamp) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::ReturnCode_t write (
                    const SetBool_Response_ & instance_data,
                    ::DDS::InstanceHandle_t handle) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::ReturnCode_t write_w_timestamp (
                    const SetBool_Response_ & instance_data,
                    ::DDS::InstanceHandle_t handle,
                    const ::DDS::Time_t & source_timestamp) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::ReturnCode_t dispose (
                    const SetBool_Response_ & instance_data,
                    ::DDS::InstanceHandle_t handle) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::ReturnCode_t dispose_w_timestamp (
                    const SetBool_Response_ & instance_data,
                    ::DDS::InstanceHandle_t handle,
                    const ::DDS::Time_t & source_timestamp) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::ReturnCode_t writedispose (
                    const SetBool_Response_ & instance_data,
                    ::DDS::InstanceHandle_t handle) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::ReturnCode_t writedispose_w_timestamp (
                    const SetBool_Response_ & instance_data,
                    ::DDS::InstanceHandle_t handle,
                    const ::DDS::Time_t & source_timestamp) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::ReturnCode_t get_key_value (
                    SetBool_Response_ & key_holder,
                    ::DDS::InstanceHandle_t handle) THROW_ORB_EXCEPTIONS;
            
                virtual ::DDS::InstanceHandle_t lookup_instance (
                    const SetBool_Response_ & instance_data) THROW_ORB_EXCEPTIONS;
            
            protected:
                SetBool_Response_DataWriter_impl ();
            
                virtual ~SetBool_Response_DataWriter_impl ();
            
                virtual DDS::ReturnCode_t init (
                                DDS::OpenSplice::Publisher *publisher,
                                DDS::OpenSplice::DomainParticipant *participant,
                                const DDS::DataWriterQos &qos,
                                DDS::OpenSplice::Topic *a_topic,
                                const char *name,
                                DDS::OpenSplice::cxxCopyIn copyIn,
                                DDS::OpenSplice::cxxCopyOut copyOut,
                                u_writerCopy writerCopy,
                                void *cdrMarshaler);
            
            private:
                SetBool_Response_DataWriter_impl (const SetBool_Response_DataWriter_impl &);
            
                SetBool_Response_DataWriter_impl & operator= (const SetBool_Response_DataWriter_impl &);
            };
            
            class ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_std_srvs SetBool_Response_DataReader_impl : public virtual SetBool_Response_DataReader,
                                                                   public ::DDS::OpenSplice::FooDataReader_impl
            {
                friend class DDS::OpenSplice::Subscriber;
                friend class SetBool_Response_TypeSupportMetaHolder;
                friend class SetBool_Response_DataReaderView_impl;