Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding data to the storage class #24

Merged
merged 52 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
568b331
creating the empty class
YonesMussa Sep 22, 2023
ffaffff
adding the data receive class to retrive the data
YonesMussa Sep 24, 2023
e2b5f29
creating data reciver class
YonesMussa Sep 24, 2023
eb6eb4f
Getting the first part done
YonesMussa Sep 25, 2023
ea5af24
fixing the error
YonesMussa Sep 25, 2023
189855f
getting the data to display
YonesMussa Sep 26, 2023
4ff137b
adding the instru to do the task
YonesMussa Sep 26, 2023
0796af6
function
ayoungdabreaker Sep 27, 2023
102e80a
Merge branch 'MSU-CSE491:main' into main
dradcl Sep 27, 2023
fa140ab
Fix DataReceiver and get agent positions
dradcl Sep 27, 2023
c17d89f
removing our test file
YonesMussa Sep 27, 2023
384163e
Refactor DataReceiver to base class
dradcl Sep 27, 2023
a9c563f
task "Gettin the action and store it in a struct unordered_map"
YonesMussa Oct 4, 2023
191586d
Merge branch 'MSU-CSE491:main' into main
dradcl Oct 5, 2023
ee38f1e
adding the tests
YonesMussa Oct 6, 2023
392ddc2
Create DoubleLinkedList
dradcl Oct 7, 2023
4af0f66
Setup DataCollection testing
dradcl Oct 9, 2023
4ba6cd2
Add more tests for DoubleLinkedList
dradcl Oct 11, 2023
0c132c8
Adding tests for all the action and moving it around
YonesMussa Oct 11, 2023
e1f9ad2
Adding tests for all the action and moving it around
YonesMussa Oct 11, 2023
63e979d
Remove DebugPrint from GridPositionReceiver
dradcl Oct 11, 2023
f6e30f8
Committing slight changes in WorldBase.hpp, DataReceiver.hpp, simple_…
Oct 11, 2023
e5a6362
changing the test filename
YonesMussa Oct 11, 2023
14e8ab5
Adding AgentData and Agentreciever with tests.
Oct 11, 2023
e05ba24
Merge branch 'main' of https://github.com/dradcl/cse_491_fall_2023_gr…
Oct 11, 2023
efb4995
changing the test filename
YonesMussa Oct 11, 2023
c1efb61
Fix AgentReceiver
dradcl Oct 11, 2023
ea2e13b
Fix data receiver tests
dradcl Oct 11, 2023
e47c011
changing the storage for actions form DataReceiver.hpp to AgentData.hpp
YonesMussa Oct 11, 2023
8c228c2
Merge remote-tracking branch 'origin/main'
YonesMussa Oct 11, 2023
5e5cc9f
fixing AgentData.hpp and implement test for AgentData.hpp
YonesMussa Oct 11, 2023
3217934
Merge remote-tracking branch 'origin/main'
YonesMussa Oct 11, 2023
32c76e3
fixing the conflicts so we can merge to main
YonesMussa Oct 11, 2023
b5bb966
fixing the conflicts so we can merge to main
YonesMussa Oct 11, 2023
0fb5569
Merge branch 'main' into main
YonesMussa Oct 11, 2023
3a99dbc
fixing the conflicts so we can merge to main
YonesMussa Oct 11, 2023
8c610cc
docstring, comments, and some improvements for the code
YonesMussa Oct 12, 2023
6ed7e87
Update README
YonesMussa Oct 12, 2023
0c57446
Update README
YonesMussa Oct 12, 2023
842803d
Update and rename README to README.md
YonesMussa Oct 12, 2023
47f4932
Update README.md
YonesMussa Oct 12, 2023
a6299d0
Update README.md
YonesMussa Oct 12, 2023
72d440e
Update README.md
YonesMussa Oct 12, 2023
b5ba97b
fix spelling for AgentReceiver in WorldBase.hpp
YonesMussa Oct 13, 2023
adc5aeb
Merge remote-tracking branch 'origin/main'
YonesMussa Oct 13, 2023
947f96b
requested changes on this pull request.
YonesMussa Oct 13, 2023
7844a16
Fix AgentReceiver crashing the program
dradcl Oct 13, 2023
4f81dd9
adding GameData and Game Reciever
ayoungdabreaker Oct 13, 2023
8730ba2
bug fixing
ayoungdabreaker Oct 13, 2023
8037f31
last changes broke the program. fixed in this commits
YonesMussa Oct 13, 2023
aaf6bd8
Merge branch 'MSU-CSE491:main' into main
dradcl Oct 16, 2023
2b12a56
Merge branch 'main' of https://github.com/dradcl/cse_491_fall_2023_gr…
Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions .github/workflows/unit_tests.yml

This file was deleted.

70 changes: 70 additions & 0 deletions docs/DataCollection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## DataCollection Namespace

The **DataCollection** namespace provides a set of classes and templates for managing and processing data related to agent actions and positions. This library offers flexibility and ease of use for storing, retrieving, and manipulating data within your C++ applications.

### Classes

1. **AgentData**

The `AgentData` class represents data collected for an agent, including their name, actions, positions, and associated IDs.

**Methods:**
- `StorePositions(cse491::GridPosition pos)`: Stores a grid position for the agent.
- `StoreAction(std::unordered_map<std::string, size_t> action)`: Stores an action for the agent.
- `StoreAgentId(int id)`: Stores an agent ID associated with an action.
- `GetActions() -> std::vector<std::unordered_map<std::string, size_t>>&`: Retrieves the stored actions.
- `SetActions(const std::vector<std::unordered_map<std::string, size_t>>& newActions)`: Sets the stored actions to a new set of actions.
- `GetPositionSize() const -> int`: Gets the size of the stored grid positions.
- `GetAgentIds() const -> std::vector<int>`: Gets the agent IDs associated with the stored actions.

2. **DataReceiver\<T\>**

The `DataReceiver` class template provides a generic way to store and retrieve data objects of a specified type.

**Methods:**
- `StoreData(T obj)`: Stores a data object of type T.
- `getStorage() -> std::vector<T>&`: Retrieves the stored data objects.

3. **AgentReceiver**

The `AgentReceiver` class extends `DataReceiver<AgentData>` and provides specific functionality for storing `AgentData` objects along with grid positions and last action IDs.

**Methods:**
- `StoreData(cse491::GridPosition pos, int last_action)`: Stores a grid position and last action ID associated with an agent.
- `GetPositionSize() -> int`: Gets the position size of the last stored `AgentData` object.
- `IsEmpty() -> bool`: Checks if the storage is empty.

### Usage

To use the **DataCollection** namespace in your C++ application, include the appropriate header files and create instances of the classes as needed. Make sure to follow the specific methods and their parameters as outlined in the class descriptions above.

```cpp
#include <DataCollection/AgentData.h>
#include <DataCollection/DataReceiver.h>
#include <DataCollection/AgentReceiver.h>

// Example Usage
DataCollection::AgentData agent;
agent.StorePositions(cse491::GridPosition(1, 2));
agent.StoreAction({{"up", 1}});
agent.StoreAgentId(101);

DataCollection::AgentReceiver agentReceiver;
agentReceiver.StoreData(cse491::GridPosition(3, 4), 102);
int positionSize = agentReceiver.GetPositionSize();
bool isEmpty = agentReceiver.IsEmpty();
```

### Installation

To use this library, simply include the necessary header files in your project. Ensure that you have C++11 or later enabled in your compiler settings.

### Contributing

Feel free to contribute by reporting issues, suggesting features, or submitting pull requests. We welcome any contributions that can improve the functionality, performance, or usability of this library.

### License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

---
98 changes: 98 additions & 0 deletions source/DataCollection/AgentData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#pragma once

#include <string>
#include <list>
#include <utility>
#include <vector>
#include <unordered_map>
#include "../core/GridPosition.hpp"

namespace DataCollection
{
/**
* @brief Represents data collected for an agent, including their name, actions, positions, and associated IDs.
*/
class AgentData {
private:
std::string name; ///< The name of the agent.
std::vector<int> actionIds; ///< IDs associated with the agent's actions.
std::vector<cse491::GridPosition> position; ///list of grid positions.
std::vector<std::unordered_map<std::string,size_t>> actions; ///< Vector of action maps.

public:
/**
* @brief Default constructor for AgentData class.
*/
// AgentData() = default;
AgentData(std::string name) : name(std::move(name)) {}

/**
* @brief Destructor for AgentData class.
*/
~AgentData() = default;

/**
* @brief Stores a grid position for the agent.
* @param pos The grid position to be stored.
*/
void StorePositions(cse491::GridPosition pos) {
position.push_back(pos);
}

/**
* @brief Stores an action for the agent.
* @param action The action to be stored.
*/
void StoreAction(std::unordered_map<std::string, size_t> action) {
actions.push_back(action);
}

/**
* @brief Stores an agent ID associated with an action.
* @param id The agent ID to be stored.
*/
void StoreAgentId(int id) {
actionIds.push_back(id);
}

/**
* @brief Retrieves the stored actions.
* @return Reference to the vector of action maps.
*/
auto& GetActions() {
return actions;
}

int GetActionSize() const {
return actions.size();
}

/**
* @brief Sets the stored actions to a new set of actions.
* @param newActions The new set of actions to be stored.
*/
void SetActions(const std::vector<std::unordered_map<std::string, size_t>>& newActions) {
actions = newActions;
}

/**
* @brief Gets the size of the stored grid positions.
* @return The number of stored grid positions.
*/
int GetPositionSize() const {
return position.size();
}

/**
* @brief Gets the agent IDs associated with the stored actions.
* @return The vector of agent IDs.
*/
auto GetAgentIds() const {
return actionIds;
}

std::string GetName() const {
return name;
}
};
} // namespace DataCollection
52 changes: 52 additions & 0 deletions source/DataCollection/AgentReciever.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include "DataReceiver.hpp"
#include "AgentData.hpp"

namespace DataCollection {

/**
* @brief Data receiver class specialized for storing AgentData objects.
*
* This class extends DataReceiver class and provides specific functionality
* for storing AgentData objects along with grid positions and last action IDs.
*/
class AgentReceiver : public DataReceiver<AgentData> {
private:
std::unordered_map<std::string, std::shared_ptr<AgentData>> agent_map;

public:
/**
* @brief Stores a grid position and last action ID associated with an agent.
*
* @param pos The grid position to be stored.
* @param last_action The last action ID associated with the agent.
*/
void StoreData(std::string name, cse491::GridPosition pos, int last_action) {
std::shared_ptr<AgentData> agent = GetAgent(name);
agent->StorePositions(pos);
// agent->StoreAction(last_action);
StoreIntoStorage(*agent);
}

void AddAgent(const std::string& name) {
AgentData agent(name);
agent_map[name] = std::make_shared<AgentData>(agent);
}

std::shared_ptr<AgentData> GetAgent(const std::string& name)
{
if (agent_map.find(name)==agent_map.end()) {
AddAgent(name);
return agent_map[name];
}
else {
return agent_map[name];
}
}

AgentData GetAgentData(const std::string& name) {
return *agent_map[name];
}
};
} // namespace DataCollection
52 changes: 52 additions & 0 deletions source/DataCollection/DataReceiver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include <vector>
namespace DataCollection {

/**
* @brief Generic data receiver template class.
*
* This class provides a template for storing and retrieving data objects of a specified type.
* @tparam T The type of data to be stored.
*/
template <typename T>
class DataReceiver {
public:
/**
* @brief Default constructor for DataReceiver class.
*/
DataReceiver() = default;

/**
* @brief Virtual destructor for DataReceiver class.
*/
virtual ~DataReceiver() = default;

/**
* @brief Retrieves the stored data objects.
* @return Reference to the vector containing stored data objects.
*/
std::vector<T>& getStorage() {
return storage;
}

/**
* @brief Store a data object into the storage
* @param obj The data object to store
*/
void StoreIntoStorage(T obj){
storage.push_back(obj);
}

/**
* @brief Checks if the storage is empty.
* @return True if the storage is empty, false otherwise.
*/
bool IsEmpty() {
return storage.empty();
}

protected:
std::vector<T> storage; ///< Vector to store shared_ptr data objects of type T.
};
} // namespace DataCollection
Loading