Skip to content

Commit 2d5fbab

Browse files
committed
Add spike channel caching when stream name changes
1 parent a34b3f7 commit 2d5fbab

3 files changed

Lines changed: 39 additions & 11 deletions

File tree

Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,22 @@ void SpikeDisplayCanvas::update()
145145

146146
if (cache)
147147
{
148+
//TODO: Should be able to call spikeChannel->getStreamIndex() here...
149+
int streamIdx = 0;
150+
for (auto& stream : processor->getDataStreams())
151+
{
152+
if (stream->getStreamId() == processor->getSpikeChannel(i)->getStreamId())
153+
break;
154+
streamIdx++;
155+
}
156+
148157
if (cache->hasCachedDisplaySettings(cacheKey))
149158
{
150159
applyCachedDisplaySettings(i, cacheKey);
151160
}
152-
else if (cache->findSimilarKey(cacheKey).size() > 0)
161+
else if (cache->findSimilarKey(cacheKey, streamIdx).size() > 0)
153162
{
154-
applyCachedDisplaySettings(i, cache->findSimilarKey(cacheKey));
163+
applyCachedDisplaySettings(i, cache->findSimilarKey(cacheKey, streamIdx));
155164
}
156165
}
157166

Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,41 @@ class SpikeDisplayCache
8181
return thresholds.count(cacheKey) > 0;
8282
};
8383

84-
std::string findSimilarKey(std::string key)
84+
std::string findSimilarKey(std::string key, int streamIndex)
8585
{
8686
std::vector<std::string> keys = extract_keys(ranges);
87+
88+
unsigned sourcePos = 0;
89+
unsigned streamPos = key.find_first_of("|");
90+
unsigned namePos = key.find_last_of("|");
91+
92+
// First check for a source ID change (match only stream + electrode name)
8793
for (int i = 0; i < keys.size(); i++)
8894
{
89-
std::string partToMatch = key.substr(3, key.length() - 3);
90-
std::string possibleMatch = keys[i].substr(3, keys[i].length() - 3);
95+
std::string partToMatch = key.substr(streamPos, key.length() - streamPos);
96+
std::string possibleMatch = keys[i].substr(streamPos, keys[i].length() - streamPos);
9197
if (partToMatch.compare(possibleMatch) == 0)
9298
return keys[i];
9399
}
100+
101+
// Next check for a stream name change (match only node + electrode name)
102+
std::vector<std::string> matches;
103+
for (int i = 0; i < keys.size(); i++)
104+
{
105+
int namePos2 = keys[i].find_last_of("|");
106+
std::string partToMatch = key.substr(sourcePos, streamPos - sourcePos) + key.substr(namePos, key.length() - namePos);
107+
std::string possibleMatch = keys[i].substr(sourcePos, streamPos - sourcePos) + keys[i].substr(namePos2, keys[i].length() - namePos2);
108+
if (partToMatch.compare(possibleMatch) == 0)
109+
matches.push_back(keys[i]);
110+
}
111+
112+
// Check if multiple matches, if so, default to stream index
113+
if (matches.size() == 1)
114+
return matches[0];
115+
else if (matches.size() > streamIndex)
116+
return matches[streamIndex];
117+
118+
// No match found
94119
return "";
95120
}
96121

leetcode

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)