How do I create relationship diagram using plantuml with lines touching the exact field - plantuml

I have successfully created the ERD with standard notations as per the UML with reference to ERD Sample
But I want to make lines exactly touching the field names as specified in this question ERD Or UML
is there and inbuilt facility available in plantuml or should I simply alter the x y position of the svg element using CSS ?

In theory it can be done using arrows from/to class members. However, it doesn't work as you'd expect:
#startuml
' hide the spot
hide circle
' avoid problems with angled crows feet
skinparam linetype ortho
entity "Entity01" as e01 {
* e1_id : number <<generated>>
__
* name : text
description : text
}
entity "Entity02" as e02 {
* e2_id : number <<generated>>
__
* e1_id : number <<FK>>
other_details : text
}
entity "Entity03" as e03 {
* e3_id : number <<generated>>
__
e1_id : number <<FK>>
other_details : text
}
e01 ||.left.o{ e02::e1_id
e01 |o.right.o{ e03::e1_id
#enduml
I'd call it a bug in PlantUML, because the lines end in the center of the entity rather than its edge. You could possibly get it fixed by reporting it. However, I doubt you can get a result as nice as the diagram in your question.
Playing around with up/down and left to right direction gets me a better result:
#startuml
' hide the spot
hide circle
' avoid problems with angled crows feet
skinparam linetype ortho
left to right direction
entity "Entity01" as e01 {
* e1_id : number <<generated>>
__
* name : text
description : text
}
entity "Entity02" as e02 {
* e2_id : number <<generated>>
__
* e1_id : number <<FK>>
other_details : text
}
entity "Entity03" as e03 {
* e3_id : number <<generated>>
__
e1_id : number <<FK>>
other_details : text
}
e01::e1_id ||.up.o{ e02::e1_id
e01::e1_id |o.down.o{ e03::e1_id
#enduml
But, again, I doubt this will work with your example. You can try!
Edit: Looking at this example, you can see that it's pretty close to the example you stated. I think the key is left to right direction.

Related

New to NoSQL and a little confused with creating collections

Im a student just starting out on NoSQL and its just not clicking with me. im a little confused on a few points.
Any help would be greatly appreciated
1.Can documents belong to multiple collections?
2.Have I the correct syntax here for creating the Collection?
The pic is the collection er and a is just a snippet of the full er.
db.Animal.insert ( {
“animal_ID” : “XXXXXXX “,
“common_name” : “Red Squirrel”,
“IUCN” : “Least Concern (declining)”,
“photo” : “qs451xkx6qf4j”,
“extinct” : {
“when” : “null “,
“reason” : “null”
},
“invasive” : {
“threat_level” : “null”,
“threat” : “null”,
“how_to_help” : “null”
},
“native” : {
“endangerment” : “population declining“,
“how_to_help” : “providing a little extra food, planting some red squirrel-friendly shrubs and reporting any red or grey squirrel activity”
},
“Fact_sheet” : “{
“fact_id” : “ “,
“animal_id” : “ XXXXXXX “,
“order” : “ Rodentia “,
“family” : “Sciuridae “ ,
“species” : “Sciurus vulgaris “ ,
“size” : “body length 19 to 23 cm, tail length 15 to 20 cm “ ,
“weight” : “250 to 340 g “ ,
“lifespan” : “3 years , 7 to 10 in captivity “ ,
“extra” : “In Norse mythology, Ratatoskr is a red squirrel who runs up and down with messages in the world tree, Yggdrasil, and spreads gossip “ ,
“habitat” : { [
“name” : “woodland “,
“description” : “a low-density forest forming open habitats with plenty of sunlight and limited shade “
]
});
Can documents belong to multiple collections?
In MongoDB, no. In other databases, I don't know.
2.Have I the correct syntax here for creating the Collection?
To create a collection you would use https://docs.mongodb.com/manual/reference/method/db.createCollection/. This call also permits you to pass various collection options.
You are inserting a document. In MongoDB when a document is inserted, if the destination collection doesn't exist, it is created automatically by the server.

What strategy can I use to OCR Magic the Gathering corner text?

I need to recognize the text in the bottom left corner on Magic the Gathering paper cards (last design). Here an example:
If the text is like this
I want to retrieve the following text:
198/280 U
M20 EN
(I don't need the card author name - Lake Hurwitz in this example)
What OCR library can I use? I've tried with Tesseract without any tuning but the results are not correct. Any advice or link to a project that already does this stuff?
You can make it with tesseract (3.04.01) by sanitizing your image a bit
like in below code
import numpy as np
import cv2
def prepro(zone, prefix):
filename = 'stackmagic.png'
oriimg = cv2.imread(filename)
#keep the interesting part
(a,b,c,d) = zone
text_zone = oriimg[a:b, c:d]
height, width, depth = text_zone.shape
#resize it to be bigger (so less pixelized)
H = 50
imgScale = H/height
newX,newY = text_zone.shape[1]*imgScale, text_zone.shape[0]*imgScale
newimg = cv2.resize(text_zone,(int(newX),int(newY)))
#binarize it
gray = cv2.cvtColor(newimg, cv2.COLOR_BGR2GRAY)
th, img = cv2.threshold(gray, 130, 255, cv2.THRESH_BINARY);
#erode it
kernel = np.ones((1,1),np.uint8)
erosion = cv2.erode(img,kernel,iterations = 1)
cv2.imwrite(prefix+'_ero.png', erosion)
cv2.imshow("Show by CV2",erosion)
cv2.waitKey(0)
prepro((16,27, 6,130), 'upzone')
prepro((27,36, 6,130), 'downzone')
from your cropped image
you get
the upper part:
and the lower part:
and tesseract does seem to be able to extract
xx$ tesseract upzone_ero.png stdout
198/ 280 U
xx$ tesseract downzone_ero.png stdout
M20 ~ EN Duluu Hun-nu
Notice that we fail to extract Luke, but hopefully you were not interested in him/it :)
There are other tools but that'd be advertising stuff and be subjective..

using lookup tables to plot a ggplot and table

I'm creating a shiny app and i'm letting the user choose what data that should be displayed in a plot and a table. This choice is done through 3 different input variables that contain 14, 4 and two choices respectivly.
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput(inputId = "DataSource", label = "Data source", choices =
c("Restoration plots", "all semi natural grasslands")),
selectInput(inputId = "Variabel", label = "Variable", choices =
choicesVariables)),
#choicesVariables definition is omitted here, because it's very long but it
#contains 14 string values
selectInput(inputId = "Factor", label = "Factor", choices = c("Company
type", "Region and type of application", "Approved or not approved
applications", "Age group" ))
),
dashboardBody(
plotOutput("thePlot"),
tableOutput("theTable")
))
This adds up to 73 choices (yes, i know the math doesn't add up there, but some choices are invalid). I would like to do this using a lookup table so a created one with every valid combination of choices like this:
rad1<-c(rep("Company type",20), rep("Region and type of application",20),
rep("Approved or not approved applications", 13), rep("Age group", 20))
rad2<-choicesVariable[c(1:14,1,4,5,9,10,11, 1:14,1,4,5,9,10,11, 1:7,9:14,
1:14,1,4,5,9,10,11)]
rad3<-c(rep("Restoration plots",14),rep("all semi natural grasslands",6),
rep("Restoration plots",14), rep("all semi natural grasslands",6),
rep("Restoration plots",27), rep("all semi natural grasslands",6))
rad4<-1:73
letaLista<-data.frame(rad1,rad2,rad3, rad4)
colnames(letaLista) <- c("Factor", "Variabel", "rest_alla", "id")
Now its easy to use subset to only get the choice that the user made. But how do i use this information to plot the plot and table without using a 73 line long ifelse statment?
I tried to create some sort of multidimensional array that could hold all the tables (and one for the plots) but i couldn't make it work. My experience with these kind of arrays is limited and this might be a simple issue, but any hints would be helpful!
My dataset that is the foundation for the plots and table consists of dataframe with 23 variables, factors and numerical. The plots and tabels are then created using the following code for all 73 combinations
s_A1 <- summarySE(Samlad_info, measurevar="Dist_brukcentrum",
groupvars="Companytype")
s_A1 <- s_A1[2:6,]
p_A1=ggplot(s_A1, aes(x=Companytype,
y=Dist_brukcentrum))+geom_bar(position=position_dodge(), stat="identity") +
geom_errorbar(aes(ymin=Dist_brukcentrum-se,
ymax=Dist_brukcentrum+se),width=.2,position=position_dodge(.9))+
scale_y_continuous(name = "") + scale_x_discrete(name = "")
where summarySE is the following function, burrowed from cookbook for R
summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=TRUE,
conf.interval=.95, .drop=TRUE) {
# New version of length which can handle NA's: if na.rm==T, don't count them
length2 <- function (x, na.rm=FALSE) {
if (na.rm) sum(!is.na(x))
else length(x)
}
# This does the summary. For each group's data frame, return a vector with
# N, mean, and sd
datac <- ddply(data, groupvars, .drop=.drop,
.fun = function(xx, col) {
c(N = length2(xx[[col]], na.rm=na.rm),
mean = mean (xx[[col]], na.rm=na.rm),
sd = sd (xx[[col]], na.rm=na.rm)
)
},
measurevar
)
# Rename the "mean" column
datac <- rename(datac, c("mean" = measurevar))
datac$se <- datac$sd / sqrt(datac$N) # Calculate standard error of the mean
# Confidence interval multiplier for standard error
# Calculate t-statistic for confidence interval:
# e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
ciMult <- qt(conf.interval/2 + .5, datac$N-1)
datac$ci <- datac$se * ciMult
return(datac)
}
The code in it's entirety is a bit to large but i hope this may clarify what i'm trying to do.
Well, thanks to florian's comment i think i might have found a solution my self. I'll present it here but leave the question open as there is probably far neater ways of doing it.
I rigged up the plots (that was created as lists by ggplot) into a list
plotList <- list(p_A1, p_A2, p_A3...)
tableList <- list(s_A1, s_A2, s_A3...)
I then used subset on my lookup table to get the matching id of the list to select the right plot and table.
output$thePlot <-renderPlot({
plotValue<-subset(letaLista, letaLista$Factor==input$Factor &
letaLista$Variabel== input$Variabel & letaLista$rest_alla==input$DataSource)
plotList[as.integer(plotValue[1,4])]
})
output$theTable <-renderTable({
plotValue<-subset(letaLista, letaLista$Factor==input$Factor &
letaLista$Variabel== input$Variabel & letaLista$rest_alla==input$DataSource)
skriva <- tableList[as.integer(plotValue[4])]
print(skriva)
})

matlab assigning text file data to age and gender

Okay so my assignment is for an engineering project and I have talked to my teacher many times but without much success. the code reads data that comes from a rotary encoder in a text file. The question I have is how do I make two sets of arrays with age and gender and link it to each text file thats read in. For example the first text file comes from a girl that is 10; that spun a crank and output data to a text file. How do i code so that someway i can assign the first text file to an age and gender? Heres my code so far any help is appreciated.
%% ME 208 Project Group 21
clear; close all; clc;
%Constants
dt=.1;
%Translate Data
mass = 10; %values are in units of Kilograms
radius = 1; %values are in units of meters
inertia = mass*radius^(2);
for ii=1:2
%File Name Variable
filename=['sub_' num2str(ii) '.txt'];
%Data is Collected
Data1=dlmread(filename,'\t',0,0);
%Times for data
t1=dt:dt:length(Data1)*dt;
%Vel
[ang_vel1, ang_acc1]=dxdt_d2xdt2(Data1,2,dt);
torq1 = inertia*ang_acc1;
%Calculations of parameters
meanrt1(ii) = rms(torq1);
maxrt1(ii) = max(torq1);
end
%Plot
figure(1);plot(t1,torq1,t2,torq2); grid minor;

Why is NSLayoutAttributeCenterX an 'Invalid pairing' with NSLayoutAttributeWidth

I am trying to have the auto layout manager adjust the center point of a view, based on the width of the super view. I don't understand why that is an 'Invalid Pairing' of the attributes (as told by the crash and NSInvalidArgumentException)
UIView *ac;
NSLayoutConstraint *cXloc = [NSLayoutConstraint constraintWithItem:ac
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:ac.superview
attribute:NSLayoutAttributeWidth
multiplier:.1
constant:x*ac.superview.frame.size.width*.2];
[ac.superview addConstraint:cXloc];
Could someone explain why this is an 'Invalid paring' and how I should approach this?
Thanks
It is the limitation of the current implementation of Auto Layout. However, you can easily work around it since all the constrains are linear and NSLayoutAttributes are correlated. For example, say, the constraint you want is:
subview.centerX = m * superview.width + c;
You can express it as a relationship between tow centerXs:
// Since width == 2 * centerX
subview.centerX = m * 2 * superview.centerX + c;
If you relate ac's AttributeCenterX to its superview's AttributeCenterX, AttributeLeading, or AttributeTrailing, you should be able to express your desired constraint using the multiplier and constraint. Keep in mind that the constant is evaluated only when the constraint is created, and your example's constant wouldn't update as ac.superview's width changes.
If you can express in words how you'd like ac positioned relative to its superview, we can suggest a constraint.
Edit
Here's an example with 5 NSButtons. They themselves and the space between them expand so that the spaces are 30% as wide as the buttons, all the buttons have the same width, and all the spaces have the same width. Creating 4 invisible NSViews just for spacing is pretty cumbersome, especially considering you've got it working outside of autolayout. But in case you're curious:
// Assuming these NSViews and NSButtons exist,
//NSView* superview ;
//NSButton *buttonOne, *buttonTwo, *buttonThree, *buttonFour, *buttonFive ;
[superView removeConstraints:superView.constraints] ;
// Create empty NSViews to fill the space between the 5 buttons.
NSView* spaceOne = [NSView new] ;
NSView* spaceTwo = [NSView new] ;
NSView* spaceThree = [NSView new] ;
NSView* spaceFour = [NSView new] ;
spaceOne.translatesAutoresizingMaskIntoConstraints = NO ;
spaceTwo.translatesAutoresizingMaskIntoConstraints = NO ;
spaceThree.translatesAutoresizingMaskIntoConstraints = NO ;
spaceFour.translatesAutoresizingMaskIntoConstraints = NO ;
[superView addSubview:spaceOne] ;
[superView addSubview:spaceTwo] ;
[superView addSubview:spaceThree] ;
[superView addSubview:spaceFour] ;
NSDictionary* views = NSDictionaryOfVariableBindings(superView,buttonOne,buttonTwo,buttonThree,buttonFour,buttonFive,spaceOne,spaceTwo,spaceThree,spaceFour) ;
// Vertically align buttonOne to its superview however you like.
[superView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:#"V:|-[buttonOne]" options:0 metrics:nil views:views ] ] ;
// Make the "space" NSViews' widths equal and >= 10. Make the buttons' widths equal.
[superView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:#"H:|[buttonOne][spaceOne(>=10)][buttonTwo(==buttonOne)][spaceTwo(==spaceOne)][buttonThree(==buttonOne)][spaceThree(==spaceOne)][buttonFour(==buttonOne)][spaceFour(==spaceOne)][buttonFive(==buttonOne)]|" options: NSLayoutFormatAlignAllCenterY metrics:nil views:views ] ] ;
// Make the "space" NSViews' widths 30% of the NSButtons' widths.
[superView addConstraint: [NSLayoutConstraint constraintWithItem: spaceOne
attribute: NSLayoutAttributeWidth
relatedBy: NSLayoutRelationEqual
toItem: buttonOne
attribute: NSLayoutAttributeWidth
multiplier: 0.3
constant: 0 ] ] ;
Based on an0's answer, and assuming you have an NSArray containing your buttons, the following should space the buttons equally within the superview:
NSUInteger currentButton = 1;
for (UIButton *button in self.buttons)
{
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:2.0 * (CGFloat) currentButton / (CGFloat) (self.buttons.count + 1) constant:0.0]];
currentButton++;
}
If you're looking to have your programmatically generated views to fit its superview's width. You can use the constraint pairing of NSLayoutAttributeLeading and attribute:NSLayoutAttributeCenterX
You have to make the proper calculation in order to get the right multiplier. Calculation involves the total count of the views to be laid out and the index of the current view.
//Caculate constraint multiplier from parentView CenterX.
//This sets the width of the button relative to parentView.
// A value of 2 = Full width.
CGFloat multiplier = 2/(arr.count/counter);
[parentView addConstraint:[NSLayoutConstraint constraintWithItem:btn
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual toItem:parentView
attribute:NSLayoutAttributeCenterX multiplier:multiplier constant:0]];
This will distribute the views width to fill its superview.

Resources