How to make new column (new feature) in Orange Python Script Widget? - orange

i have Feature 1 , Feature 2, Feature 3
How to add new "Feature 4" and "Feature 5 ", ?
Code below only return original Data Table (out_data = in_data)
what i want is **out_data = in_data + new feature "Feature 4" + new feature "Feature 5" **
Note: Feature 4 is continous and Feature 5 is discrete ("yes" or "no")
def add_new_column(data):
domain = Domain(data.domain.variables,data.domain.class_vars,data.domain.metas)
return Table(domain, data)
out_data = add_new_column(in_data)

Try the code below:
from Orange.data import ContinuousVariable, DiscreteVariable, Domain
var1 = ContinuousVariable("Feature 4")
var2 = DiscreteVariable("Feature 5", values=["yes", "no"])
domain = in_data.domain
new_domain = Domain(attributes=domain.attributes + (var1, var2), metas=domain.metas, class_vars=domain.class_vars)
out_data = in_data.transform(new_domain)

Related

Alluvial plot - reorder lodes

I have created an alluvial plot but, for visibility purposes I would like to move one lode in one of the axes: more specifically I would like the "NA" of the "Type of surgery" to be at the top so the last 4 axes are aligned.
This is the code I used on R:
aes(y = ID, axis1 = Reason, axis2 = Response, axis3=Type_of_surgery, axis4=Margins, axis5=RT_post_op, axis6=Chemo_post_op)) +
geom_alluvium(aes(fill = Type_of_surgery), width = 1/12,aes.bind = TRUE) +
geom_flow(aes.bind = TRUE) +
geom_stratum(width = 1/3, fill = "grey", color = "white") +
geom_label(stat = "stratum", aes(label = after_stat(stratum))) +
scale_x_discrete(limits = c("Reason", "Response","Type of surgery", "Margins","RT post op", "Chemo post-op"), expand = c(0.1,0.1)) +
scale_fill_brewer(type = "qual", palette = "Pastel1") +
ggtitle("TBC") ```
This is the plot I obtained:
[Alluvial plot][1]
[1]: https://i.stack.imgur.com/nDCIZ.png
I am beginning on the world of coding so any help would be most welcome,
Thank you all for your help,
JB

Libre Office custom Dialog Table

I am creating a custom Dialog where the user is supposed to select one of multiple possible entries. I use a List Box to list the possible entries to be selected from.
There are multiple variables for each row, therefore I would like to use a table to properly align the entries. Is there a possibility to do so?
What i have:
abcdefg hijkl mnopq
abcd efghijk lmno
What i want:
abcdefg hijkl mnopq
abcd efghilkl mno
Use a fixed-width font for the list box, and pad the strings with spaces.
Sub PaddedListboxItems
oListBox.addItems(Array(
PaddedItem(Array("abcdefg", "hijkl", "mnopq")),
PaddedItem(Array("abcd", "efghijk", "lmno"))), 0)
End Sub
Function PaddedItem(item_strings As Array)
PaddedItem = PadString(item_strings(0), 10) & _
PadString(item_strings(1), 11) & item_strings(2)
End Function
Function PadString(strSource As String, lPadLen As Long)
PadString = strSource & " "
If Len(strSource) < lPadLen Then
PadString = strSource & Space(lPadLen - Len(strSource))
End If
End Function
More ways to pad strings in Basic are at http://www.tek-tips.com/viewthread.cfm?qid=522164, although not all of them work in LibreOffice Basic.
Yes, it is possible.
Create a new dialog and at the bottom, add a label.
Create a new module and add following code:
Option Explicit
Option Base 0
Dim oDialog1 As Object, oDataModel As Object, oListener As Object
Sub OpenDialog()
Dim oGrid As Object, oGridModel As Object, oColumnModel As Object, oCol As Object
Dim oLabel1 As Object, rect(3) As Integer
DialogLibraries.LoadLibrary("Standard")
oDialog1 = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
oGridModel = oDialog1.getModel().createInstance("com.sun.star.awt.grid.UnoControlGridModel")
oLabel1 = oDialog1.getModel().getByName("Label1")
rect(0) = oLabel1.getPropertyValue("PositionX")
rect(1) = 10
rect(2) = oLabel1.getPropertyValue("Width")
rect(3) = oLabel1.getPropertyValue("PositionY") - 2*rect(1)
With oGridModel
.PositionX = rect(0)
.PositionY = rect(1)
.Width = rect(2)
.Height = rect(3)
End With
oColumnModel = oGridModel.ColumnModel
oCol = oColumnModel.createColumn()
oCol.Title = "Column 1"
oColumnModel.addColumn(oCol)
oCol = oColumnModel.createColumn()
oCol.Title = "Column 2"
oColumnModel.addColumn(oCol)
oCol = oColumnModel.createColumn()
oCol.Title = "Column 3"
oColumnModel.addColumn(oCol)
oDialog1.getModel().insertByName("grid", oGridModel)
oGrid = oDialog1.getControl("grid")
oListener = (CreateUnoListener("grid_", "com.sun.star.awt.grid.XGridSelectionListener"))
oGrid.addSelectionListener(oListener)
oDataModel = oGridModel.GridDataModel
oDataModel.addRow("a", Array("abcdefg", "hijkl", "mnopq"))
oDataModel.addRow("b", Array("abcd", "efghijk", "lmno"))
oDialog1.execute()
oDialog1.dispose()
End Sub
To get the values of the selected row, add a listener for the grid_selectionChanged event:
Sub grid_selectionChanged(ev)
Dim oRows() As Object, oLabel1 As Object, sCells(2) As String
oRows = ev.Source.getSelectedRows()
oLabel1 = oDialog1.getModel().getByName("Label1")
sCells(0) = oDataModel.getRowData(oRows(0))(0)
sCells(1) = oDataModel.getRowData(oRows(0))(1)
sCells(2) = oDataModel.getRowData(oRows(0))(2)
oLabel1.setPropertyValue("Label", "Selected values: " + sCells(0) + "," + sCells(1) + "," + sCells(2))
End Sub
If you did all correctly, by running OpenDialog you should get your grid:

How to validate some of the dynamic table cells in asp.net

As the code below, I need to create a dynamic table in which each cell gets validated. If there is any wrong input, error message will pop up for that specific cell. Now our BA doesn’t want to display multiple error messages for each column. Only simply display one error message for each column like last name like “Last Name is invalid” no matter how many last names are invalid. How can I accomplish this? Is that possible?
Thanks in advance. I will really appreciate your response.
Thanks,
Dev2016
Protected Sub ShowBoxes(ByVal startRow As Integer, ByVal nRowsAdd As Integer)
Dim d As Integer = 10
For d = startRow To (startRow + nRowsAdd - 1)
Dim row As New HtmlTableRow()
row.VAlign = "center"
row.Attributes("class") = "bgA"
row.ID = "IndivRow_" & d.ToString
Dim col1 As New HtmlTableCell()
col1.Align = "center"
col1.Width = 29
col1.InnerHtml = (d + 1).ToString
Dim col2 As New HtmlTableCell()
col2.Width = 53
col2.VAlign = "left"
Dim txt2 As New TextBox()
txt2.ID = "Last_" & d.ToString
txt2.Columns = "29"
txt2.MaxLength = "30"
Dim reg2 As New RegularExpressionValidator()
reg2.ID = "regLast_" & d.ToString
reg2.ControlToValidate = "Last_" & d.ToString
reg2.ValidationExpression = "^[a-zA-Z0-9""()-. '\s]{1,50}$"
reg2.ErrorMessage = "Last Name on line " & (d + 1).ToString & " contains invalid characters."
reg2.Text = "*"
reg2.Display = ValidatorDisplay.Static
reg2.ValidationGroup = "SubmitFormClient"
reg2.SetFocusOnError = True
col2.Controls.Add(txt2)
col2.Controls.Add(reg2)
Dim col3 As New HtmlTableCell()
col3.Width = 53
col3.VAlign = "left"
Dim txt3 As New TextBox()
txt3.ID = "First_" & d.ToString
txt3.MaxLength = "30"
Dim reg3 As New RegularExpressionValidator()
reg3.ID = "regFirst_" & d.ToString
reg3.ControlToValidate = "First_" & d.ToString
reg3.ValidationExpression = "^[a-zA-Z0-9""()-. '\s]{1,50}$"
reg3.ErrorMessage = "First Name on line " & (d + 1).ToString & " contains invalid characters."
reg3.Text = "*"
reg3.Display = ValidatorDisplay.Static
reg3.ValidationGroup = "SubmitFormClient"
reg3.SetFocusOnError = True
col3.Controls.Add(txt3)
col3.controls.add(reg3)
row.Cells.Add(col1)
row.Cells.Add(col2)
row.Cells.Add(col3)
tableIndiv.Rows.Add(row)
Next d
End Sub

Need to convert a simple number set to text with if, then, else in Crystal

Fairly new to Crystal Reports. Need to convert numbers to text in a formula. This is what I've tried, along with several others, but returns an error. Any suggestions helpful!
IF {Ref_Referrals.ReferralStatusID} = 1 then totext "Open"
or if 2 = then totext = "Closed-Sale"
or if 3 = then totext = "Closed-Expired"
or if 4 = then totext = "Closed-No Interest"
or if 5 = then totext = "Closed-Extended"
or if 6 = then totext = "Closed-Sale(Auto)"
or if 7 = then totext = "Closed-Future Interest"
or if 8 = then totext = "Closed Not Qualified"
else totext is null
You'll want to use a CASE-statement for this.
select {Ref_Referrals.ReferralStatusID}
case 1 : "Open"
case 2 : "Closed-Sale"
case 3 : "Closed-Expired"
case 4 : "Closed-No Interest"
.
.
.
default : ""
If you're doing this inside the actual Crystal Report, you need to use the Switch statement.
Switch ({Ref_Referrals.ReferralStatusID} = 1, "Open",
{Ref_Referrals.ReferralStatusID} = 2, "Closed-Sale",
{Ref_Referrals.ReferralStatusID} = 3, "Closed-Expired",
{Ref_Referrals.ReferralStatusID} = 4, "Closed-No Interest",
{Ref_Referrals.ReferralStatusID} = 5, "Closed-Extended",
{Ref_Referrals.ReferralStatusID} = 6, "Closed-Sale(Auto)",
{Ref_Referrals.ReferralStatusID} = 7, "Closed-Future Interest",
{Ref_Referrals.ReferralStatusID} = 8, "Closed Not Qualified",
True, "")
The last line of the Switch returns a 0-length string if none of the previous 8 conditions are true.
Edit: If for some reason you still really want to do this with IF THEN ELSE, you would need to use nested ELSE IFs. The SWITCH is designed to replace nested ELSE IF, though. Just a thought.

When exporting Word review comments, how do you reference the sentence related to a comment?

I am trying to export a Word document's review comments. I want to export the sentence selection that was commented on followed by the comment.
Screen shot of the image: http://jspeaks.com/mswordcomment.png
I have found code to loop through the document comments, but I cannot figure out how to reference the sentence selection that the comment was related to.
The current logic is:
Sub ExportComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & cmt.Initial & cmt.Index & "," & cmt.Range.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s
End Sub
I tinkered with Selection.Range, however I cannot determine the proper object or property that contains the referenced sentence.
I would like to produce output like the following (if we use the example in picture above):
Sentence: Here are more sentences that contain interesting facts - Comment: This is an interesting fact.
Sentence: Here are more sentences that contain interesting facts. Here are more sentences that contain interesting facts. - Comment: This is a very interesting fact
I found someone on another site to solve this question.
The key to the solution is: cmt.Scope.FormattedText
Here is the function revised:
Sub ExportComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "Text: " & cmt.Scope.FormattedText & " -> "
s = s & "Comments: " & cmt.Initial & cmt.Index & ":" & cmt.Range.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s
End Sub
I have gathered several pieces of code and came to this solution:
Sub CopyCommentsToExcel()
'Create in Word vba
'TODO: set a reference to the Excel object library (Tools --> Reference --> Microsoft Excel 12.0 Object library)
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim i As Integer
Dim HeadingRow As Integer
HeadingRow = 3
Dim cmtRef As Range
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add ' create a new workbook
With xlWB.Worksheets(1)
' Create report info
.Cells(1, 1).Formula = "Reviewed document:"
' Create Heading
.Cells(HeadingRow, 1).Formula = "Index"
.Cells(HeadingRow, 2).Formula = "Page"
.Cells(HeadingRow, 3).Formula = "Line"
.Cells(HeadingRow, 4).Formula = "Comment"
.Cells(HeadingRow, 5).Formula = "Reviewer"
.Cells(HeadingRow, 6).Formula = "Date"
For i = 1 To ActiveDocument.Comments.Count
.Cells(2, 1).Formula = ActiveDocument.Comments(i).Parent
.Cells(i + HeadingRow, 1).Formula = ActiveDocument.Comments(i).Index
.Cells(i + HeadingRow, 2).Formula = ActiveDocument.Comments(i).Reference.Information(wdActiveEndAdjustedPageNumber)
.Cells(i + HeadingRow, 3).Formula = ActiveDocument.Comments(i).Reference.Information(wdFirstCharacterLineNumber)
.Cells(i + HeadingRow, 4).Formula = ActiveDocument.Comments(i).Range
.Cells(i + HeadingRow, 5).Formula = ActiveDocument.Comments(i).Initial
.Cells(i + HeadingRow, 6).Formula = Format(ActiveDocument.Comments(i).Date, "dd/MM/yyyy")
' .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Parent
' .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Application
' .Cells(i + 1, 7).Formula = ActiveDocument.Comments(i).Author
Next i
End With
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
Most valuable help from Microsoft Answers