gaddox/change-log-helper


A bash script to get all changes made in a git repo, on a certain date

License: BSD-3-Clause-Clear

Language: Shell

Keywords: automation, changelog, changelog-generator


change-log-helper

A bash script to get all changes made in a git repo, on a certain date

What is this?

A helper script for complying with GNU's Coding Standards on Change Logs.

Usage Examples

To generate all the changes made to a repo on December 23rd, 2013:

$ ./change-log-helper.sh 2013-12-23

To generate all the changes between April 1st, 2012 and July 19th, 2014:

$ ./change-log-helper.sh --compare 2012-04-01 2014-07-19

Outputted Format

Example output using Amadeus' repo, where "2018-05-01" was passed as the date.

dates 2018-04-30 to 2018-05-01
diff --git a/.gitignore b/.gitignore
index 67de115..67238e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+a.out
+\#*
 src/amadeus
 src/bin/
 src/.libs
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..cc171c5
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,32 @@
+The Clear BSD License
+
+Copyright (c) 2018-present, Gaddox
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted (subject to the limitations in the disclaimer
+below) provided that the following conditions are met:
+
+     * Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+
+     * Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+
+     * Neither the name of the copyright holder nor the names of its
+     contributors may be used to endorse or promote products derived from this
+     software without specific prior written permission.
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/src/Makefile.am b/src/Makefile.am
index 0892cb8..b45d745 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,4 +8,4 @@ amadeus_LDADD = libAmadeus.la
 
 lib_LTLIBRARIES = libAmadeus.la
 libAmadeus_la_LDFLAGS = -version-info 0:0:0
-libAmadeus_la_SOURCES = main.h portfolio.cpp portfolio.h signals.cpp signals.h simulator.cpp simulator.h 
+libAmadeus_la_SOURCES = main.h portfolio.cpp portfolio.h signals.cpp signals.h simulator.cpp simulator.h logger.cpp logger.h 
diff --git a/src/logger.cpp b/src/logger.cpp
new file mode 100644
index 0000000..6050773
--- /dev/null
+++ b/src/logger.cpp
@@ -0,0 +1,52 @@
+// logger.cpp -- Simple logging object for amadeus
+
+#include "logger.h"
+#include <iostream>
+#include <ctime>
+#include <string>
+
+
+// INPUT: None
+// SIDE-EFFECTS: Creates logger object,
+//               dumps strings to clog, and set logger.startTime
+// OUTPUT: None
+logger::logger(void)
+{
+  this->startTime = clock();
+  time_t now = time(0);
+  std::string str_now(ctime(&now));
+  str_now.replace(0,4,"[");
+  str_now.replace(str_now.size()-1,1,"]");
+  std::clog << str_now << " [START] Logger started" << std::endl;
+  return;
+}
+
+// INPUT: Raw c-style string
+// SIDE-EFFECTS: Dumps string with time pre-appended to clog
+// OUTPUT: None
+template<typename T>
+void logger::operator<<(const T logMessage)
+{
+  time_t now = time(0);
+  std::string str_now(ctime(&now));
+  str_now.replace(0,4,"[");
+  str_now.replace(str_now.size()-1,1,"]");
+  std::clog << str_now << " " << logMessage << std::endl;
+  return;
+}
+
+// INPUT: None
+// SIDE-EFFECTS: Dumps strings to clog and destroy logger object
+// OUTPUT: None
+logger::~logger(void)
+{
+  time_t now = time(0);
+  std::string str_now(ctime(&now));
+  str_now.replace(0,4,"[");
+  str_now.replace(str_now.size()-1,1,"]");
+  double raw_now = clock();
+  double startTime = this->getStartTime();
+  double runningTime = (raw_now - startTime)/double(CLOCKS_PER_SEC)*1000;
+  std::clog << str_now << " [END] Logger ran for: " << runningTime << " seconds" << std::endl;
+}
+
diff --git a/src/logger.h b/src/logger.h
new file mode 100644
index 0000000..f857079
--- /dev/null
+++ b/src/logger.h
@@ -0,0 +1,19 @@
+// logger.h - Logger class header
+
+// Include guard                        
+#ifndef __LOGGER_H__
+#define __LOGGER_H__
+#include <iostream>
+
+// Class prototype
+class logger {
+ private:
+  double startTime;
+ public:
+  logger(void);
+  double getStartTime(void){return this->startTime;};
+  template<typename T> void operator<<(const T logMessage);
+  ~logger(void);
+};
+
+#endif /* __LOGGER_H__ */
diff --git a/src/main.cpp b/src/main.cpp
index 3ff4be5..aa4f0ea 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,15 +1,14 @@
 // amadeus - A screaming fast high frequency trading (HFT) engine 
-//======================================
-// Include dependencies
+
 #include "main.h"
 #include "portfolio.h"
 #include "signals.h"
 #include "simulator.h"
+#include "logger.h"
 #include <iostream>
 #include <thread>
 #include <string>
 
-// Define global variables
 // Global fee for broker's fee
 const int tradingFee = 1;
 // Global starting share price
diff --git a/src/portfolio.cpp b/src/portfolio.cpp
index 6935bef..298f2b2 100644
--- a/src/portfolio.cpp
+++ b/src/portfolio.cpp
@@ -1,6 +1,5 @@
 // portfolio.cpp - Class functions for portfolio object
-//======================================
-// Include dependencies
+
 #include "portfolio.h"
 #include "signals.h"
 #include <iostream>
@@ -16,6 +15,7 @@ portfolio::portfolio(int portfolioValue) : startingValue(portfolioValue)
   this->shares = 0;
   this->errorAmnt = 0;
   this->trading = true;
+  this->failSafe_errorAmnt = 1000;
   return;
 }
 
@@ -29,11 +29,14 @@ int portfolio::getTotalValue (void)
 }
 
 // INPUT: Generated signal from signalProcessor function
+// SIDE-EFFECTS: Dumps strings to cout
+// OUTPUT: None
 // CAVEATS: E before I for Receive
 void portfolio::receiveSignal(signal signalReceived)
 {
   switch ( signalReceived ) {
   case signal::err:
+    std::cout << "Err" << std::endl;
     this->failSafe_error(true);
     break;
   case signal::hold:
@@ -47,6 +50,7 @@ void portfolio::receiveSignal(signal signalReceived)
     this->buyStock(5);
     break;
   default:
+    std::cout << "Default " << std::endl;
     this->failSafe_error(true);
     break;
   }
@@ -56,6 +60,7 @@ void portfolio::receiveSignal(signal signalReceived)
 
 // INPUT: Requested amount of shares to be bought
 // SIDE-EFFECTS: Portfolio object's "liquidValue," "shares," and "totalValue"
+//               as well as possible strings into cout and "trading" flag
 // OUTPUT: None
 // CAVEATS: ATOMIC(?)
 void portfolio::buyStock(int shareAmnt)
@@ -67,14 +72,21 @@ void portfolio::buyStock(int shareAmnt)
     this->liquidValue -= shareCost + totalFees;
     this->shares += shareAmnt;
     this->totalValue = this->liquidValue + (sharePrice * this->shares);
-    }
-  getPortfolioInfo();
-  getSharePrice();
+    this->tradesCompleted++;
+    
+    getPortfolioInfo();
+    getSharePrice();
+  }
+  else {
+    std::cout << "Not enough cash" << std::endl;
+    this->trading = false;
+  }
   return;
 }
 
 // INPUT: Requested amount of shares to be sold
 // SIDE-EFFECTS: Portfolio object's "liquidValue," "shares," and "totalValue"
+//               as well as possible strings into cout and "trading" flag
 // OUTPUT: None
 // CAVEATS: ATOMIC(?)
 void portfolio::sellStock(int shareAmnt)
@@ -86,10 +98,16 @@ void portfolio::sellStock(int shareAmnt)
     this->liquidValue += shareCost - totalFees;
     this->shares -= shareAmnt;
     this->totalValue = this->liquidValue + (sharePrice * this->shares);
-    }
+    this->tradesCompleted++;
+    
+    getPortfolioInfo();
+    getSharePrice();
+  }
+  else {
+    std::cout << "Not enough cash" << std::endl;
+    this->trading = false;
+  }
   
-  getPortfolioInfo();
-  getSharePrice();
   return;
 }
 
@@ -101,13 +119,15 @@ void portfolio::failSafe_error(bool increment)
 {
   if (increment) {
     this->errorAmnt++;
+    std::cout << "Error incremented" << std::endl;
   }
   
   // If maximum amnt of errors exceeds incurred amnt, deconstruct self
-  if (this->errorAmnt >= this->failSafe_errorAmnt) {
+  if (this->getErrorAmnt() >= this->getFailSafe_errorAmnt()) {
+    std::cout << "Fail Safe Amount: " << this->getFailSafe_errorAmnt() << std::endl;
+    std::cout << "Error Amount: " << this->getErrorAmnt() << std::endl;
     std::cout << "Too many errors." << std::endl;
     this->trading = false;
-    return;
   }
   return;
 }
@@ -130,6 +150,8 @@ void portfolio::getPortfolioInfo(void)
             << " Total value: " << this->getTotalValue() << std::endl
             << " Liquid value: " << this->getLiquidValue() << std::endl
             << " Shares: " << this->getShares() << std::endl
+            << " Errors: " << this->getErrorAmnt() << std::endl
+            << " Trades: " << this->getTradesCompleted() << std::endl
             << std::endl;
   return;
 }
diff --git a/src/portfolio.h b/src/portfolio.h
index 6b42474..cedf196 100644
--- a/src/portfolio.h
+++ b/src/portfolio.h
@@ -1,14 +1,13 @@
 // portfolio.h - Portfolio class header
-//======================================
-// Include guard                        
-#ifndef PORTFOLIO_H
-#define PORTFOLIO_H
+
+#ifndef __PORTFOLIO_H__
+#define __PORTFOLIO_H__
 
 // Declared variables -- somewhere else 
 extern const int tradingFee;
 extern int sharePrice;
 
-// Forward declared variables
+// Forward declared
 enum class signal: int;
 
 // Class prototype                      
@@ -21,6 +20,7 @@ class portfolio {
   int errorAmnt;
   int failSafe_errorAmnt;
   bool trading;
+  int tradesCompleted;
  public:
   portfolio(int portfolioValue);
   bool getIfTrading(void){return this->trading;};
@@ -28,6 +28,9 @@ class portfolio {
   int getLiquidValue(void){return this->liquidValue;};
   int getTotalValue(void);
   int getShares(void){return this->shares;};
+  int getErrorAmnt(void){return this->errorAmnt;};
+  int getFailSafe_errorAmnt(void){return this->failSafe_errorAmnt;};
+  int getTradesCompleted(void){return this->tradesCompleted;};
   void getPortfolioInfo(void);
   void getSharePrice(void);
   void receiveSignal(signal signalReceived);
@@ -37,4 +40,4 @@ class portfolio {
   ~portfolio(){};
 };
 
-#endif /* PORTFOLIO_H */
+#endif /* __PORTFOLIO_H__ */
diff --git a/src/signals.cpp b/src/signals.cpp
index 667880b..216cb5c 100644
--- a/src/signals.cpp
+++ b/src/signals.cpp
@@ -42,6 +42,7 @@ signal signalProcessor(int price)
   if (std::cin.fail()) {
     // Wrong input
     signalProcessed = signal::err;
+    std::cout << "CIN fail flag triggered" << std::endl;
   }
   else if (price < 25 && price > 0) {
     // Buy
@@ -58,6 +59,11 @@ signal signalProcessor(int price)
   else {
     // Catch-all
     signalProcessed = signal::err;
+    std::cout << "Price is: " << price << std::endl
+              << "price < 25 && price > 0 is: " << (price < 25 && price > 0) << std::endl
+              << "price >= 25 && price <= 100 is: " << (price >= 25 && price <= 100) << std::endl
+              << "price > 100 is: " << (price > 100) << std::endl
+              << "Some other error happened" << std::endl;
   }
   
   return signalProcessed;
diff --git a/src/signals.h b/src/signals.h
index 972616b..45ded2b 100644
--- a/src/signals.h
+++ b/src/signals.h
@@ -1,10 +1,8 @@
 // signals.h - Signal generator header
-//======================================
-// Include guard 
-#ifndef SIGNALS_H
-#define SIGNALS_H
 
-// Include dependencies
+#ifndef __SIGNALS_H__
+#define __SIGNALS_H__
+
 #include <string>
 
 // Type definitions 
@@ -16,4 +14,4 @@ enum class signal: int { err = -1, hold = 0, sell = 1, buy = 2 };
 signal signalProcessor(int price);
 std::string signalDecoder(signal signalProcessed);
 
-#endif /* SIGNALS_H */
+#endif /* __SIGNALS_H__ */
diff --git a/src/simulator.cpp b/src/simulator.cpp
index ec94fb6..b64bb36 100644
--- a/src/simulator.cpp
+++ b/src/simulator.cpp
@@ -1,6 +1,5 @@
 // simulator.cpp - Simulates stock price for testing
-//======================================
-// Include dependencies
+
 #include "simulator.h"
 #include <random>
 #include <chrono>
@@ -13,14 +12,16 @@ void priceSimulator(void)
 {
   // Setup pseudo-random generator
   std::random_device rd;  
-  std::mt19937 gen(rd());
-  // Negative numbers for testing errors, range of sharePrice: -20 to 120
-  std::uniform_int_distribution<> dis(-1, 120); 
+  std::mt19937 gen1(rd());
+  std::ranlux48 gen2(rd());
+  // Negative numbers for testing errors, range of sharePrice: 0 to 120
+  std::uniform_int_distribution<> externalVariance(2, 120); 
+  std::uniform_int_distribution<> internalVariance(0, 1); 
   
   // Change "sharePrice" every second, as long as the function is running
   while (true) {
-    sharePrice = dis(gen);
-    std::this_thread::sleep_for(std::chrono::seconds(1));
+    sharePrice = externalVariance(gen1) - internalVariance(gen2);
+    std::this_thread::sleep_for(std::chrono::microseconds(1));
   }
   
   return;

Project Statistics

Sourcerank 3
Repository Size 28.3 KB
Stars 0
Forks 0
Watchers 1
Open issues 0
Dependencies 0
Contributors 1
Tags 2
Created
Last updated
Last pushed

Top Contributors See all

gaddox

Recent Tags See all

v1.0.1 May 02, 2018
v1.0.0 May 02, 2018

Something wrong with this page? Make a suggestion

Last synced: 2018-05-03 00:00:20 UTC

Login to resync this repository