Create table in dynamoDB(pynamoDB) with following model , but here 2nd class(Ran) is a attr in 1st class and 3rd class(Ran2) used as attr in 2nd - dynamodb-queries

class MigrationPlan:
name: str [primary key]
asgs: List[Ran]
class Ran:
random_id: str [primary key]
old_asg_id: str [range key]
old_asg: Ran2
new_asg: Ran2
order_id: int
order_arrived: bool
scaling_disabled: bool
class Ran2:
asg_id: str [primary key]
instance_type: str
instance_count: int
current_instance_count: int
asg_created: bool
hosts_arrived: bool
hosts_transferred: bool
scaling_planner_status: str
migrate_service_workflow: Optional[str]
Here MigrationPlan class contains Ran as an attribute which is another class and similarly class Ran contains attributes as Ran2 which is again another class.How can I do this?

Related

Value assignment in Alloy and use of Enum

How to assign variable in Alloy?
Sig ClassA{
variable_1: String,
variable_2: Int
}
Sig ClassB{
variable_1: String,
variable_2: Int
}
pred isLess[a:ClassA,b:ClassB]{
a.variable_2 < b.variable_2
}
assert integrityTest{
all a:ClassA,b:ClassB| isLess[a,b]
}
Now I want to check counterexample of variables when I assign some bigger value in a.variable_2 than b.variable_2. But I am not sure how to assign variable in Alloy. Only thing I came up with is following but it is not working-
pred assignValue[a:ClassA]{
a.variable_2 = Int[4]
}
However, I believe it will only check the equality with 4 and return as false. It has nothing to do with the assignment. So my question is how should I produce counterexample when a.variable_2>b.variable_2
And How can I use Enum of Int in alloy? Like- Enum MetricValue {1,2,3,4,5} to assign a.variable 1.
EDIT
I am still having trouble finding the counterexample, even though I can find one by manually checking when I toggle the value of variable_2 of ca and cb.
sig ClassA{
variable_1: String,
variable_2 = Int
}
sig CA extends ClassA{}{
variable_2 = 1
}
sig ClassB{
variable_1: String,
variable_2 = Int
}
sig CB extends ClassB{}{
variable_2 = 4
}
pred checkAllConstraint [ca: ClassA, cb: ClassB] {
ca.variable_2 > cb.variable_2 }
assert checkAll{
all ca: ClassA, cb: ClassB | checkAllConstraint[ca,cb]
}
check checkAll for 15
You can restrain a field to a single value through facts. In your case, signature facts come handy.
It will look like this:
sig ClassA{
variable_1: String,
variable_2: Int
}{
variable_1="hello world"
variable_2=4
}
To bound a field to one value amongst a set, you can use the "in" keyword instead of "=" as follows:
sig ClassA{
variable_1: String,
variable_2: Int
}{
variable_1 in ("hello" + "world")
variable_2 in (1+2+3+4)
}
Note that in Alloy + is a UNION operator. It doesn't sum nor concatenate as you might expect.
EDIT
It doesn't work for 2 reasons:
you wrote : variable_2 = Int instead of variable_2: Int.
By doing so, no valid instance contains atoms typed by CA or CB, because e.g. ClassA.variable2 is constrained to be the set of all integers and CA.variable2 is constrained to be 1
no String atom is defined. That's one of Alloy's weird part. If you want to use Strings in your model, you need to have string litterals somewhere specified, e.g. in a fact.
Here's your model, corrected:
sig ClassA{
variable_1: String,
variable_2 : Int
}
sig CA extends ClassA{}{
variable_2 = 1
}
sig ClassB{
variable_1: String,
variable_2 : Int
}
sig CB extends ClassB{}{
variable_2 = 4
}
pred checkAllConstraint [ca: ClassA, cb: ClassB] {
ca.variable_2 > cb.variable_2 }
assert checkAll{
all ca: ClassA, cb: ClassB | checkAllConstraint[ca,cb]
}
check checkAll for 15
fact { String in ("test"+"test2"+"test3"+"test4")}
If you still have questions, please create a new one.
-

Inserting a node (containing str and bool values) into an array C++

Anyways, I am working on a trivia game for a school project. I am reading in questions and answers from a CSV file that will be displayed to the user through the terminal. But I am having trouble inserting my nodes into the array.
My tactic here is to read in question first then read the correct answer in second, and the last three answers are the incorrect answers which will be shuffled later.
ifstream questionFile("questions.csv");
getline(questionFile, header);
if(questionFile.is_open())
{
string line;
while(getline(questionFile, line))
{
stringstream ss;
ss << line;
string item;
getline(ss, item, ',');
question = item;
getline(ss, item, ',');
answer1 = item;
getline(ss, item, ',');
answer2 = item;
getline(ss, item, ',');
answer3 = item;
getline(ss, item, ',');
answer4 = item;
g.insertAndShuffle(question, answer1, answer2, answer3, answer4);
}
}
questionFile.close()
I then pass these values into a function which will assign the answer strings into a node which will also hold a boolean value (correct answer holds true). Here's my issue I think... I then pass pointers to these nodes along with the question into an array[5] so that I can shuffle array[1]-[5] to randomize the answers.
Here is the function:
string* Game::insertAndShuffle(string question, string answer1, string answer2, string answer3, string answer4)
{
Answer *nodeC = new Answer(answer1, true);
Answer *node1 = new Answer(answer2, false);
Answer *node2 = new Answer(answer3, false);
Answer *node3 = new Answer(answer4, false);
quizArray[0] = question;
quizArray[1] = nodeC;
quizArray[2] = node1;
quizArray[3] = node2;
quizArray[4] = node3;
random_shuffle(&quizArray[1], &quizArray[5]);
return quizArray;
}
The class containing the function:
class Game
{
public:
bool isAsked;
string quizArray[5];
int questionNum = 1;
bool letsPlay = false;
string* insertAndShuffle(string question, string answer1, string answer2, string answer3, string answer4);
string askQuestions(string* quizArray);
bool startGame(bool letsPlay, string playerName);
// bool checkAnswer(string playerResponse, string answer1);
private:
Answer *nodeC;
Answer *node1;
Answer *node2;
Answer *node3;
};
And the struct being used for answers:
struct Answer
{
string answer;
bool isCorrect;
Answer();
Answer(string item, bool value)
{
answer = item;
isCorrect = value;
}
};
There seems to be a problem when I am trying to access the the pointer to the struct through the class function. Here is my error:
./project.hpp:22:2: error: unknown type name 'Answer'
Answer *nodeC;
^
./project.hpp:23:2: error: unknown type name 'Answer'
Answer *node1;
^
./project.hpp:24:2: error: unknown type name 'Answer'
Answer *node2;
^
./project.hpp:25:2: error: unknown type name 'Answer'
Answer *node3;
^
./project.hpp:43:2: error: C++ requires a type specifier for all declarations
CorrectAnswer();
^
./project.hpp:44:2: error: C++ requires a type specifier for all declarations
CorrectAnswer(string item, bool value)
^
In file included from projectMain.cpp:8:
./project.cpp:85:22: error: no matching constructor for initialization of 'Answer'
Answer *nodeC = new Answer(answer1, true);

std::map find fails when key is pointer

I am unable to get the std::map find to locate the correct row in the std::map. The key is a class pointer and I have created a struct (tdEcApplDataMapEq) to compare the class's binary arrays for a match.'
The problem is it doesn't work. I call FoEcApplData::operator== when the find starts. It says the first entry does not a match and then the find returns out pointing to the first item on the std::map list. There is no attempt by find to search the other map entries. Also the one match test failed (false), so why is find saying its a match?
This probably has something to do with the std::map declaration. std::map says the third argument is for std::less, but I am doing a == vs. <.
If I change it to do < the same this happens. It enters FoEcApplData::operator< which return a true on the first check and find search stops with the search pointing to the 1st entry in the list.
How do I get find() to use the custom struct for the search?
My example adds 10 rows to FdTEcApplDataMap. It copies the CDH_DISABLE_XACT182 class into hold for the search later. I then do the find() test using hold as the search key.
Inside entry1
Inside entry2
Inside entry3<== this is the one I am searching for
Inside entry4
Inside entry5
Inside entry6
Inside entry7
Inside entry8
Inside entry9
Inside entry10
Inside entry1
This is the find:
auto hazard = ExcludedCmdDict.find(&hold);
if(hazard != ExcludedCmdDict.end())
{
std::cout << "found it " << hazard->second << std::endl;
}
This is the compare function being used:
bool FoEcApplData::operator==( const FoEcApplData& FoEcApplDataObject) const {
if(myNumOfBytes <= FoEcApplDataObject.NumOfBytes())
{
const EcTOctet* temp;
temp = FoEcApplDataObject.Data() ;
for(EcTInt i = 0; i < myNumOfBytes ; i++)
{
if(myData[i] != temp[i])
{
return false ;
}
}
return true;
}
else // myNumOfBytes > FoEcApplDataObject.NumOfBytes()
{
const EcTOctet* temp;
temp = FoEcApplDataObject.Data() ;
for(EcTInt i = 0; i < FoEcApplDataObject.NumOfBytes(); i++)
{
if(myData[i] != temp[i])
{
return false ;
}
}
return true;
}
}
This is the declaration for the std::map.
/*
Custom less for find on the FdTEcApplDataMap.
Needed since we are using pointers.
Returns - true - match, false - no match
node - pointer to the item you are looking for
node2 - pointer to an item on the list
*/
struct tdEcApplDataMapEq {
bool operator()(FoEcApplData *const& node, FoEcApplData *const& node2) const
{
return *node == *node2;
}
};
typedef std::map< FoEcApplData *, std::string, tdEcApplDataMapEq> FdTEcApplDataMap;
std::map expects the compare function to work like std::less. You need to use something along the lines of:
struct tdEcApplDataMapEq {
bool operator()(FoEcApplData *const& node, FoEcApplData *const& node2) const
{
return (*node < *node2); // Implement operator<() function for FoEcApplData
}
};
While at it, change the name of the struct to reflect the fact that it is trying to compute "less than".
struct tdEcApplDataMapLess {
bool operator()(FoEcApplData *const& node, FoEcApplData *const& node2) const
{
return (*node < *node2); // Implement operator<() function for FoEcApplData
}
};

How to use linq to process and conditionally read text file into a List<class> or a dictionary

How to use Linq to process the following scenario: here is the sample test file
"
^name A
valueA
^name B
^name C
valueC
"
I hope linq can process it and read them into a List or a dictionary
public class NameValue
{
public string colname;
public string colvalue;
}
like this:
({"name_A","valueA"},{"name_B",""},{"name_C","valueC"})
Basically each name line starts with a ^ and followed by a value line, but not every name has a value attached to it in the text file. In the name line, replace any space with _.
Thx!
Here is some code which should do what you want to do:
https://ideone.com/ThplS6
using System;
using System.Text.RegularExpressions;
using System.Linq;
public class Test
{
public static void Main()
{
var input = #"^name A
valueA
^name B
^name C
valueC";
var pattern = #"\^[^\^]*";
var matches = Regex.Matches(input, pattern, RegexOptions.Multiline);
var dict = matches.Cast<Match>().ToDictionary(s => s.Value.Split('\n')[0].Trim().Remove(0, 1), s => s.Value.Split('\n')[1].Trim());
Console.WriteLine(dict.Aggregate(String.Empty, (s, s1) => s + s1.Key + ":" + s1.Value +"|"));
}
}
It uses Regex and LINQ.

Initializing an array of UDT in VB6

I have declared an UDT and I need to initialise an array with specific records of the UDT, how would I do it at the module level.
Here is what I've tried
Public Type MyType
id As Integer
name As String
values As Double
End Type
private MY_TYPES(1) As MyType
My_TYPES(0) = newMyType(1, "Item 1", 15.9)
My_TYPES(1) = newMyType(2, "Item 2", 30.2)
Private Function newMyType(byval id as Integer, byval name as String, _
byval v as Double) As MyType
Dim t As MyType
t.id = id
t.name = name
t.value = v
newMyType = t
End Function
The error I get is Invalid outside procedure
As you can see it I try to reproduce what would be static initialization of a java Collection like a List or Set
I would like to expose the collection as constant, how could I achive this?
you have to place the following 2 lines in a sub, and then call the sub to init the udt
My_TYPES(0) = newMyType(1, "Item 1", 15.9)
My_TYPES(1) = newMyType(2, "Item 2", 30.2)
or you can can place these 2 lines in the working sub inside an if..then with a module level init boolean

Resources