问:
Not able to convert .xsd to .cs using xsd.exe command. It generates empty class
I have following schema. I am trying to convert it into a .cs file. Is there any workaround. I have tried it using xsd.exe command from Visual Studio Command prompt.</p>

```<code>  <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="mfp:anaf:dgti:f3000:declaratie:v1" targetNamespace="mfp:anaf:dgti:f3000:declaratie:v1" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.02" xml:lang="ro">
        <xs:element name="F3000" type="F3000Type"/>
        <xs:complexType name="F3000Type">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="inregistrare" type="InregistrareType" minOccurs="0" maxOccurs="300000"/>
                        <xs:element name="poolReport" type="PoolReportType" minOccurs="0" maxOccurs="300000"/>
                    </xs:sequence>
                    <xs:attribute name="luna" type="IntInt12_12SType" use="required"/>
                    <xs:attribute name="an" type="IntInt2014_2100SType" use="required"/>
                    <xs:attribute name="cui" type="CuiSType" use="required"/>
                    <xs:attribute name="giin" type="Str20"/>
                    <xs:attribute name="denumire" type="Str200" use="required"/>
                    <xs:attribute name="nume_declar" type="Str75" use="required"/>
                    <xs:attribute name="prenume_declar" type="Str75" use="required"/>
                    <xs:attribute name="functie_declar" type="Str75" use="required"/>
                    <xs:attribute name="totalPlata_A" type="IntPoz15SType" use="required"/>
                    <xs:attribute name="exista" type="IntPoz1SType"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="InregistrareType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="persoane" type="PersoaneType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="cont" type="ContType" minOccurs="0"/>
                        <xs:element name="sponsored" type="SponsoredType" minOccurs="0" maxOccurs="1"/>
                    </xs:sequence>
                    <xs:attribute name="d_rec1" type="IntInt1_2SType"/>
                    <xs:attribute name="id_inreg" type="IntPoz15SType" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="PersoaneType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="tin" type="TinType" maxOccurs="unbounded"/>
                        <xs:element name="rezidenta" type="RezidentaType" maxOccurs="unbounded"/>
                        <xs:element name="nationalitate" type="NationalitateType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="adresa" type="AdresaType" maxOccurs="unbounded"/>
                        <xs:element name="denumire" type="DenumireType" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="tip_declar" type="IntInt1_3SType" use="required"/>
                    <xs:attribute name="tip_ctr" type="Str_listaTipCtrSType"/>
                    <xs:attribute name="tip_pers" type="IntInt1_8SType"/>
                    <xs:attribute name="alt_tip_pers" type="Str50"/>
                    <xs:attribute name="tip_detinator_cont" type="Str_listaTipDetinatorSType"/>
                    <xs:attribute name="data_nastere" type="Str10"/>
                    <xs:attribute name="oras_nastere" type="Str100"/>
                    <xs:attribute name="sub_oras_nastere" type="Str100"/>
                    <xs:attribute name="cod_tara_nastere" type="IntPoz3SType"/>
                    <xs:attribute name="fost_nume_tara" type="Str100"/>
                    <xs:attribute name="cui_pers" type="CifSType"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="TinType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_in" type="Str50"/>
                    <xs:attribute name="cod_tara" type="IntPoz3SType" use="required"/>
                    <xs:attribute name="identif" type="Str50" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="RezidentaType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="indiciu" type="IntInt1_4SType"/>
                    <xs:attribute name="detalii_indiciu" type="Str75"/>
                    <xs:attribute name="cod_tara_rez" type="IntPoz3SType" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="NationalitateType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="nationalitate" type="Str3" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="AdresaType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_adresa" type="Str7"/>
                    <xs:attribute name="cod_tara_adresa" type="IntPoz3SType" use="required"/>
                    <xs:attribute name="adresa_free" type="Str200"/>
                    <xs:attribute name="strada" type="Str75"/>
                    <xs:attribute name="bloc" type="Str50"/>
                    <xs:attribute name="ap" type="Str50"/>
                    <xs:attribute name="etaj" type="Str50"/>
                    <xs:attribute name="nume_district" type="Str75"/>
                    <xs:attribute name="pob" type="Str10"/>
                    <xs:attribute name="cod_postal" type="Str10"/>
                    <xs:attribute name="oras" type="Str75" use="required"/>
                    <xs:attribute name="sub_tara" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="DenumireType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="titlu" type="TitluType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="generatie" type="GeneratieType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="sufix" type="SufixType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="mijl" type="MijlType" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="tip_nume" type="Str7"/>
                    <xs:attribute name="gen" type="Str1"/>
                    <xs:attribute name="denumire" type="Str200"/>
                    <xs:attribute name="titlu_prec" type="Str75"/>
                    <xs:attribute name="suf_general" type="Str75"/>
                    <xs:attribute name="nume1" type="Str75"/>
                    <xs:attribute name="tip_nume1" type="Str50"/>
                    <xs:attribute name="nume2" type="Str75"/>
                    <xs:attribute name="tip_nume2" type="Str50"/>
                    <xs:attribute name="tip_prefix" type="Str75"/>
                    <xs:attribute name="prefix" type="Str75"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="TitluType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="titlu" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="GeneratieType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="identificator" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="SufixType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="suf" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="MijlType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_nume_mij" type="Str75"/>
                    <xs:attribute name="nume_mij" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="ContType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="plati" type="PlatiType" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="id_cont" type="Str30" use="required"/>
                    <xs:attribute name="tip_numar_cont" type="Str7" use="required"/>
                    <xs:attribute name="det_cont" type="Str75"/>
                    <xs:attribute name="swift" type="Str8"/>
                    <xs:attribute name="nr_cont" type="Str50" use="required"/>
                    <xs:attribute name="tip_cont" type="IntInt1_6SType" use="required"/>
                    <xs:attribute name="trat_cont" type="Str6"/>
                    <xs:attribute name="autocertificare" type="IntInt0_1SType" use="required"/>
                    <xs:attribute name="cont_inchis" type="IntInt0_1SType"/>
                    <xs:attribute name="cont_nedocumentat" type="IntInt0_1SType"/>
                    <xs:attribute name="cont_inactiv" type="IntInt0_1SType"/>
                    <xs:attribute name="valoare_sold" type="DblPoz15_2SType"/>
                    <xs:attribute name="data_sold" type="DateSType" use="required"/>
                    <xs:attribute name="moneda_sold" type="Str3" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="PlatiType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_suma" type="IntInt1_7SType" use="required"/>
                    <xs:attribute name="detalii_plata" type="Str50"/>
                    <xs:attribute name="tax_rate" type="DblPoz2_2SType"/>
                    <xs:attribute name="suma" type="DblPoz15_2SType"/>
                    <xs:attribute name="data" type="DateSType" use="required"/>
                    <xs:attribute name="moneda_plata" type="Str3" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="SponsoredType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="rezidentaS" type="RezidentaSType" maxOccurs="unbounded"/>
                        <xs:element name="adresaS" type="AdresaType" maxOccurs="unbounded"/>
                        <xs:element name="denumireS" type="DenumireSType" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="tip_entitate" type="IntInt1_2SType" use="required"/>
                    <xs:attribute name="identif" type="Str50" use="required"/>
                    <xs:attribute name="cui" type="CuiSType"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="PoolReportType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="sold" type="SoldType" maxOccurs="unbounded"/>
                        <xs:element name="sponsored" type="SponsoredType" maxOccurs="1"/>
                    </xs:sequence>
                    <xs:attribute name="d_rec1" type="IntInt1_2SType"/>
                    <xs:attribute name="id_inreg" type="IntPoz15SType" use="required"/>
                    <xs:attribute name="tip_detinator" type="Str8"/>
                    <xs:attribute name="nr_conturi" type="IntPoz15SType"/>
                    <xs:attribute name="balanta" type="DblPoz15_2SType"/>
                    <xs:attribute name="moneda" type="Str3"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="SoldType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="val_sold" type="DblPoz15_2SType" use="required"/>
                    <xs:attribute name="moneda_sold" type="Str3" use="required"/>
                    <xs:attribute name="data_sold" type="DateSType" use="required"/>
                    <xs:attribute name="tip_detalii" type="Str200"/>
                    <xs:attribute name="detalii" type="Str200"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="RezidentaSType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="cod_tara_rez" type="IntPoz3SType" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="DenumireSType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_nume" type="Str7"/>
                    <xs:attribute name="denumire" type="Str200" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:simpleType name="IntInt12_12SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="12"/>
                <xs:maxInclusive value="12"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt2014_2100SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="2014"/>
                <xs:maxInclusive value="2100"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="CuiSType">
            <xs:restriction base="xs:token">
                <xs:pattern value="[1-9]\d{1,9}"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str20">
            <xs:restriction base="xs:string">
                <xs:maxLength value="20"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="CifSType">
            <xs:restriction base="xs:token">
                <xs:pattern value="[1-9]\d{12}|[1-9]\d{1,9}"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str25">
            <xs:restriction base="xs:string">
                <xs:maxLength value="25"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str200">
            <xs:restriction base="xs:string">
                <xs:maxLength value="200"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str75">
            <xs:restriction base="xs:string">
                <xs:maxLength value="75"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntPoz15SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="999999999999999"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntPoz3SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="999"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntPoz1SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="9"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_2SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="2"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_3SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="3"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str_listaTipCtrSType">
            <xs:restriction base="xs:string">
                <xs:maxLength value="256"/>
                <xs:enumeration value="CRS801"/>
                <xs:enumeration value="CRS802"/>
                <xs:enumeration value="CRS803"/>
                <xs:enumeration value="CRS804"/>
                <xs:enumeration value="CRS805"/>
                <xs:enumeration value="CRS806"/>
                <xs:enumeration value="CRS807"/>
                <xs:enumeration value="CRS808"/>
                <xs:enumeration value="CRS809"/>
                <xs:enumeration value="CRS810"/>
                <xs:enumeration value="CRS811"/>
                <xs:enumeration value="CRS812"/>
                <xs:enumeration value="CRS813"/>
                <xs:enumeration value="CRS819"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_8SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="8"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str50">
            <xs:restriction base="xs:string">
                <xs:maxLength value="50"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str_listaTipDetinatorSType">
            <xs:restriction base="xs:string">
                <xs:maxLength value="256"/>
                <xs:enumeration value="CRS101"/>
                <xs:enumeration value="CRS102"/>
                <xs:enumeration value="CRS103"/>
                <xs:enumeration value="FATCA101"/>
                <xs:enumeration value="FATCA102"/>
                <xs:enumeration value="FATCA103"/>
                <xs:enumeration value="FATCA104"/>
                <xs:enumeration value="FATCA105"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str10">
            <xs:restriction base="xs:string">
                <xs:maxLength value="10"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str100">
            <xs:restriction base="xs:string">
                <xs:maxLength value="100"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str2">
            <xs:restriction base="xs:string">
                <xs:maxLength value="2"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str3">
            <xs:restriction base="xs:string">
                <xs:maxLength value="3"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_4SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="4"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str7">
            <xs:restriction base="xs:string">
                <xs:maxLength value="7"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str1">
            <xs:restriction base="xs:string">
                <xs:maxLength value="1"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str8">
            <xs:restriction base="xs:string">
                <xs:maxLength value="8"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_7SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="7"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_6SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="6"/>
            </xs:restriction>
        </xs:simpleType>

        <xs:simpleType name="Str30">
            <xs:restriction base="xs:string">
                <xs:maxLength value="30"/>
            </xs:restriction>
        </xs:simpleType>

        <xs:simpleType name="Str6">
            <xs:restriction base="xs:string">
                <xs:maxLength value="6"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt0_1SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="1"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="DateSType">
            <xs:restriction base="xs:token">
                <xs:pattern value="([1-9]|0[1-9]|[12][0-9]|3[01])\.([1-9]|0[1-9]|1[012])\.\d{4}"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="DblPoz15_2SType">
            <xs:restriction base="xs:double">
                <xs:minInclusive value="0."/>
                <xs:pattern value="\d{0,15}(\.\d{0,2})?"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="DblPoz2_2SType">
            <xs:restriction base="xs:double">
                <xs:minInclusive value="0."/>
                <xs:pattern value="\d{0,2}(\.\d{0,2})?"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntPoz2SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="99"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:schema>
</code>```

<p>When I run xsd.exe command, it generates following empty class.</p>

```<code>//--------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Xml.Serialization;

//
// This source code was auto-generated by xsd, Version=4.0.30319.17929.
//

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="mfp:anaf:dgti:f3000:declaratie:v1")]
[System.Xml.Serialization.XmlRootAttribute("F3000", Namespace="mfp:anaf:dgti:f3000:declaratie:v1", IsNullable=false)]
public partial class F3000Type {
}
</code>```

答: For workaround, try Xsd2Code - free and available from CodePlex. Visual Studio Plugin to right-click on XSD and generate .cs file for it.</p>

Body:
I have following schema. I am trying to convert it into a .cs file. Is there any workaround. I have tried it using xsd.exe command from Visual Studio Command prompt.

  <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="mfp:anaf:dgti:f3000:declaratie:v1" targetNamespace="mfp:anaf:dgti:f3000:declaratie:v1" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.02" xml:lang="ro">
        <xs:element name="F3000" type="F3000Type"/>
        <xs:complexType name="F3000Type">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="inregistrare" type="InregistrareType" minOccurs="0" maxOccurs="300000"/>
                        <xs:element name="poolReport" type="PoolReportType" minOccurs="0" maxOccurs="300000"/>
                    </xs:sequence>
                    <xs:attribute name="luna" type="IntInt12_12SType" use="required"/>
                    <xs:attribute name="an" type="IntInt2014_2100SType" use="required"/>
                    <xs:attribute name="cui" type="CuiSType" use="required"/>
                    <xs:attribute name="giin" type="Str20"/>
                    <xs:attribute name="denumire" type="Str200" use="required"/>
                    <xs:attribute name="nume_declar" type="Str75" use="required"/>
                    <xs:attribute name="prenume_declar" type="Str75" use="required"/>
                    <xs:attribute name="functie_declar" type="Str75" use="required"/>
                    <xs:attribute name="totalPlata_A" type="IntPoz15SType" use="required"/>
                    <xs:attribute name="exista" type="IntPoz1SType"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="InregistrareType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="persoane" type="PersoaneType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="cont" type="ContType" minOccurs="0"/>
                        <xs:element name="sponsored" type="SponsoredType" minOccurs="0" maxOccurs="1"/>
                    </xs:sequence>
                    <xs:attribute name="d_rec1" type="IntInt1_2SType"/>
                    <xs:attribute name="id_inreg" type="IntPoz15SType" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="PersoaneType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="tin" type="TinType" maxOccurs="unbounded"/>
                        <xs:element name="rezidenta" type="RezidentaType" maxOccurs="unbounded"/>
                        <xs:element name="nationalitate" type="NationalitateType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="adresa" type="AdresaType" maxOccurs="unbounded"/>
                        <xs:element name="denumire" type="DenumireType" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="tip_declar" type="IntInt1_3SType" use="required"/>
                    <xs:attribute name="tip_ctr" type="Str_listaTipCtrSType"/>
                    <xs:attribute name="tip_pers" type="IntInt1_8SType"/>
                    <xs:attribute name="alt_tip_pers" type="Str50"/>
                    <xs:attribute name="tip_detinator_cont" type="Str_listaTipDetinatorSType"/>
                    <xs:attribute name="data_nastere" type="Str10"/>
                    <xs:attribute name="oras_nastere" type="Str100"/>
                    <xs:attribute name="sub_oras_nastere" type="Str100"/>
                    <xs:attribute name="cod_tara_nastere" type="IntPoz3SType"/>
                    <xs:attribute name="fost_nume_tara" type="Str100"/>
                    <xs:attribute name="cui_pers" type="CifSType"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="TinType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_in" type="Str50"/>
                    <xs:attribute name="cod_tara" type="IntPoz3SType" use="required"/>
                    <xs:attribute name="identif" type="Str50" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="RezidentaType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="indiciu" type="IntInt1_4SType"/>
                    <xs:attribute name="detalii_indiciu" type="Str75"/>
                    <xs:attribute name="cod_tara_rez" type="IntPoz3SType" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="NationalitateType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="nationalitate" type="Str3" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="AdresaType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_adresa" type="Str7"/>
                    <xs:attribute name="cod_tara_adresa" type="IntPoz3SType" use="required"/>
                    <xs:attribute name="adresa_free" type="Str200"/>
                    <xs:attribute name="strada" type="Str75"/>
                    <xs:attribute name="bloc" type="Str50"/>
                    <xs:attribute name="ap" type="Str50"/>
                    <xs:attribute name="etaj" type="Str50"/>
                    <xs:attribute name="nume_district" type="Str75"/>
                    <xs:attribute name="pob" type="Str10"/>
                    <xs:attribute name="cod_postal" type="Str10"/>
                    <xs:attribute name="oras" type="Str75" use="required"/>
                    <xs:attribute name="sub_tara" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="DenumireType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="titlu" type="TitluType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="generatie" type="GeneratieType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="sufix" type="SufixType" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="mijl" type="MijlType" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="tip_nume" type="Str7"/>
                    <xs:attribute name="gen" type="Str1"/>
                    <xs:attribute name="denumire" type="Str200"/>
                    <xs:attribute name="titlu_prec" type="Str75"/>
                    <xs:attribute name="suf_general" type="Str75"/>
                    <xs:attribute name="nume1" type="Str75"/>
                    <xs:attribute name="tip_nume1" type="Str50"/>
                    <xs:attribute name="nume2" type="Str75"/>
                    <xs:attribute name="tip_nume2" type="Str50"/>
                    <xs:attribute name="tip_prefix" type="Str75"/>
                    <xs:attribute name="prefix" type="Str75"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="TitluType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="titlu" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="GeneratieType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="identificator" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="SufixType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="suf" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="MijlType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_nume_mij" type="Str75"/>
                    <xs:attribute name="nume_mij" type="Str75" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="ContType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="plati" type="PlatiType" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="id_cont" type="Str30" use="required"/>
                    <xs:attribute name="tip_numar_cont" type="Str7" use="required"/>
                    <xs:attribute name="det_cont" type="Str75"/>
                    <xs:attribute name="swift" type="Str8"/>
                    <xs:attribute name="nr_cont" type="Str50" use="required"/>
                    <xs:attribute name="tip_cont" type="IntInt1_6SType" use="required"/>
                    <xs:attribute name="trat_cont" type="Str6"/>
                    <xs:attribute name="autocertificare" type="IntInt0_1SType" use="required"/>
                    <xs:attribute name="cont_inchis" type="IntInt0_1SType"/>
                    <xs:attribute name="cont_nedocumentat" type="IntInt0_1SType"/>
                    <xs:attribute name="cont_inactiv" type="IntInt0_1SType"/>
                    <xs:attribute name="valoare_sold" type="DblPoz15_2SType"/>
                    <xs:attribute name="data_sold" type="DateSType" use="required"/>
                    <xs:attribute name="moneda_sold" type="Str3" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="PlatiType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_suma" type="IntInt1_7SType" use="required"/>
                    <xs:attribute name="detalii_plata" type="Str50"/>
                    <xs:attribute name="tax_rate" type="DblPoz2_2SType"/>
                    <xs:attribute name="suma" type="DblPoz15_2SType"/>
                    <xs:attribute name="data" type="DateSType" use="required"/>
                    <xs:attribute name="moneda_plata" type="Str3" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="SponsoredType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="rezidentaS" type="RezidentaSType" maxOccurs="unbounded"/>
                        <xs:element name="adresaS" type="AdresaType" maxOccurs="unbounded"/>
                        <xs:element name="denumireS" type="DenumireSType" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="tip_entitate" type="IntInt1_2SType" use="required"/>
                    <xs:attribute name="identif" type="Str50" use="required"/>
                    <xs:attribute name="cui" type="CuiSType"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="PoolReportType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:sequence>
                        <xs:element name="sold" type="SoldType" maxOccurs="unbounded"/>
                        <xs:element name="sponsored" type="SponsoredType" maxOccurs="1"/>
                    </xs:sequence>
                    <xs:attribute name="d_rec1" type="IntInt1_2SType"/>
                    <xs:attribute name="id_inreg" type="IntPoz15SType" use="required"/>
                    <xs:attribute name="tip_detinator" type="Str8"/>
                    <xs:attribute name="nr_conturi" type="IntPoz15SType"/>
                    <xs:attribute name="balanta" type="DblPoz15_2SType"/>
                    <xs:attribute name="moneda" type="Str3"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="SoldType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="val_sold" type="DblPoz15_2SType" use="required"/>
                    <xs:attribute name="moneda_sold" type="Str3" use="required"/>
                    <xs:attribute name="data_sold" type="DateSType" use="required"/>
                    <xs:attribute name="tip_detalii" type="Str200"/>
                    <xs:attribute name="detalii" type="Str200"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="RezidentaSType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="cod_tara_rez" type="IntPoz3SType" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="DenumireSType">
            <xs:complexContent>
                <xs:restriction base="xs:anyType">
                    <xs:attribute name="tip_nume" type="Str7"/>
                    <xs:attribute name="denumire" type="Str200" use="required"/>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        <xs:simpleType name="IntInt12_12SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="12"/>
                <xs:maxInclusive value="12"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt2014_2100SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="2014"/>
                <xs:maxInclusive value="2100"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="CuiSType">
            <xs:restriction base="xs:token">
                <xs:pattern value="[1-9]\d{1,9}"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str20">
            <xs:restriction base="xs:string">
                <xs:maxLength value="20"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="CifSType">
            <xs:restriction base="xs:token">
                <xs:pattern value="[1-9]\d{12}|[1-9]\d{1,9}"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str25">
            <xs:restriction base="xs:string">
                <xs:maxLength value="25"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str200">
            <xs:restriction base="xs:string">
                <xs:maxLength value="200"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str75">
            <xs:restriction base="xs:string">
                <xs:maxLength value="75"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntPoz15SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="999999999999999"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntPoz3SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="999"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntPoz1SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="9"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_2SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="2"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_3SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="3"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str_listaTipCtrSType">
            <xs:restriction base="xs:string">
                <xs:maxLength value="256"/>
                <xs:enumeration value="CRS801"/>
                <xs:enumeration value="CRS802"/>
                <xs:enumeration value="CRS803"/>
                <xs:enumeration value="CRS804"/>
                <xs:enumeration value="CRS805"/>
                <xs:enumeration value="CRS806"/>
                <xs:enumeration value="CRS807"/>
                <xs:enumeration value="CRS808"/>
                <xs:enumeration value="CRS809"/>
                <xs:enumeration value="CRS810"/>
                <xs:enumeration value="CRS811"/>
                <xs:enumeration value="CRS812"/>
                <xs:enumeration value="CRS813"/>
                <xs:enumeration value="CRS819"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_8SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="8"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str50">
            <xs:restriction base="xs:string">
                <xs:maxLength value="50"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str_listaTipDetinatorSType">
            <xs:restriction base="xs:string">
                <xs:maxLength value="256"/>
                <xs:enumeration value="CRS101"/>
                <xs:enumeration value="CRS102"/>
                <xs:enumeration value="CRS103"/>
                <xs:enumeration value="FATCA101"/>
                <xs:enumeration value="FATCA102"/>
                <xs:enumeration value="FATCA103"/>
                <xs:enumeration value="FATCA104"/>
                <xs:enumeration value="FATCA105"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str10">
            <xs:restriction base="xs:string">
                <xs:maxLength value="10"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str100">
            <xs:restriction base="xs:string">
                <xs:maxLength value="100"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str2">
            <xs:restriction base="xs:string">
                <xs:maxLength value="2"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str3">
            <xs:restriction base="xs:string">
                <xs:maxLength value="3"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_4SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="4"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str7">
            <xs:restriction base="xs:string">
                <xs:maxLength value="7"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str1">
            <xs:restriction base="xs:string">
                <xs:maxLength value="1"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="Str8">
            <xs:restriction base="xs:string">
                <xs:maxLength value="8"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_7SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="7"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt1_6SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="6"/>
            </xs:restriction>
        </xs:simpleType>

        <xs:simpleType name="Str30">
            <xs:restriction base="xs:string">
                <xs:maxLength value="30"/>
            </xs:restriction>
        </xs:simpleType>

        <xs:simpleType name="Str6">
            <xs:restriction base="xs:string">
                <xs:maxLength value="6"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntInt0_1SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="1"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="DateSType">
            <xs:restriction base="xs:token">
                <xs:pattern value="([1-9]|0[1-9]|[12][0-9]|3[01])\.([1-9]|0[1-9]|1[012])\.\d{4}"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="DblPoz15_2SType">
            <xs:restriction base="xs:double">
                <xs:minInclusive value="0."/>
                <xs:pattern value="\d{0,15}(\.\d{0,2})?"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="DblPoz2_2SType">
            <xs:restriction base="xs:double">
                <xs:minInclusive value="0."/>
                <xs:pattern value="\d{0,2}(\.\d{0,2})?"/>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="IntPoz2SType">
            <xs:restriction base="xs:integer">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="99"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:schema>

When I run xsd.exe command, it generates following empty class.

//--------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Xml.Serialization;

//
// This source code was auto-generated by xsd, Version=4.0.30319.17929.
//

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="mfp:anaf:dgti:f3000:declaratie:v1")]
[System.Xml.Serialization.XmlRootAttribute("F3000", Namespace="mfp:anaf:dgti:f3000:declaratie:v1", IsNullable=false)]
public partial class F3000Type {
}


来源: stackexchange

问:
Can someone help me with onclick events created programmatically?
I have a script that generates a set of divs programmatically, but I can't figure out how to get the onclick events to work for each div independently.

sample code snippet

```<code>for (i = 0;i < allEntries.length;i++) {
    //Build a div for this entry
    var containerID = "dayTimeMinutesContainer-" + allEntries[i][10] + "-" + allEntries[i][6];
    var contSubj = allEntries[i][4];
    var divid = allEntries[i][12];

    dojo.query(dojo.create("div",{id:divid},containerID))
        .onclick(function(){alert(contSubj);  //returns the last subject for all entries  ???
        });
}
</code>```

As shown in the code snippet, the onclick event fires for each div created - but it ALWAYS returns the Subject (contSubj) from the last entry processed in the loop, regardless of the entry clicked.

I'm a dojo rookie, so I apologize if this seems to be a simple oversight.  I've spent hours seeking a solution, but haven't found anything similar.  Can someone point me in the right direction?  How can I create onclick events to work for each individual divid processed?

答:
Please add the code directly in the post and not as image.

The issue is not with the event. It the variable contSubj which is the culprit. In JavaScript a variable is function scoped. You have defined the contSubj outside the function scope of click callback function. So it will always have the value of the last item of for loop.

ContentLicense: CC BY-SA 3.0

Body:
I have a script that generates a set of divs programmatically, but I can't figure out how to get the onclick events to work for each div independently.

sample code snippet

for (i = 0;i < allEntries.length;i++) {
    //Build a div for this entry
    var containerID = "dayTimeMinutesContainer-" + allEntries[i][10] + "-" + allEntries[i][6];
    var contSubj = allEntries[i][4];
    var divid = allEntries[i][12];

    dojo.query(dojo.create("div",{id:divid},containerID))
        .onclick(function(){alert(contSubj);  //returns the last subject for all entries  ???
        });
}

As shown in the code snippet, the onclick event fires for each div created - but it ALWAYS returns the Subject (contSubj) from the last entry processed in the loop, regardless of the entry clicked.

I'm a dojo rookie, so I apologize if this seems to be a simple oversight.  I've spent hours seeking a solution, but haven't found anything similar.  Can someone point me in the right direction?  How can I create onclick events to work for each individual divid processed?


问:
Calculate mean of serial pairs of values by group
Objective: calculate the mean of each pair of values by group in a dataframe

Example data:

```<code>mtcars[1:10, 1:2] %>%
   arrange(cyl)

 mpg cyl
22.8   4
24.4   4
22.8   4
21.0   6
21.0   6
21.4   6
18.1   6
19.2   6
18.7   8
14.3   8
</code>```

Expected Output:

```<code>mpg   cyl   avg
22.8   4     -
24.4   4     23.6
22.8   4     23.6
21.0   6     -
21.0   6     21.0
21.4   6     21.2
18.1   6     19.75
19.2   6     18.65
18.7   8     -
14.3   8     16.5
</code>```

Thought I could use dplyr::lag or dplyr::slice to do this, but haven't got it working.  Not married to dplyr, any solution would be appreciated...

Attempt:

```<code>group_by(mtcars, gear) %>%
   summarise(pairmean=mean(c(mpg, lag(mpg))))
</code>```

答:
We need a rolling mean (rollmean from zoo) grouped by 'cyl'

```<code>library(dplyr)
library(zoo)
mtcars[1:10, 1:2] %>%
        arrange(cyl) %>%
        group_by(cyl) %>%
        mutate(avg = rollmean(mpg, 2, na.pad = TRUE, align = "right"))
</code>```

Body:
Objective: calculate the mean of each pair of values by group in a dataframe

Example data:

mtcars[1:10, 1:2] %>%
   arrange(cyl)

 mpg cyl
22.8   4
24.4   4
22.8   4
21.0   6
21.0   6
21.4   6
18.1   6
19.2   6
18.7   8
14.3   8

Expected Output:

mpg   cyl   avg
22.8   4     -
24.4   4     23.6
22.8   4     23.6
21.0   6     -
21.0   6     21.0
21.4   6     21.2
18.1   6     19.75
19.2   6     18.65
18.7   8     -
14.3   8     16.5

Thought I could use dplyr::lag or dplyr::slice to do this, but haven't got it working.  Not married to dplyr, any solution would be appreciated...

Attempt:

group_by(mtcars, gear) %>%
   summarise(pairmean=mean(c(mpg, lag(mpg))))

Body:
We need a rolling mean (rollmean from zoo) grouped by 'cyl'

library(dplyr)
library(zoo)
mtcars[1:10, 1:2] %>%
        arrange(cyl) %>%
        group_by(cyl) %>%
        mutate(avg = rollmean(mpg, 2, na.pad = TRUE, align = "right"))


问:
Dynamically append dict into empty Pandas.Dataframe
I am parsing line by line through a massive text file (~10M lines) by regex to filter and clean up what need.

Each matched.groupdict() returns {'col1:'...','col2:'...','col3:'...'} which I would like to collect into a DataFrame. Just like a database, each entry would had its own index.

Over the past few days, I did tons of research on SO, Pandas.DataFrame docs, Coursera on DataFrames and nothing worked. Most solutions suggest creating a list of my groupdict() and then create a DataFrame, but that takes too much memory and I need it to be more dynamic.

What should I do?

```<code>pattern = re.compile("(?P<col1>...)(?P<col2>...)(?P<col3>...)")
data = pd.DataFrame()
with open("massive.txt", 'r') as massive:
    for line in massive:
        matched = pattern.search(line)
        if(matched):
            data.append(matched.groupdict(), ignore_index=True)

data
Empty DataFrame
Columns: []
Index: []
</code>```

答:
... silly me</p>

```<code>...
data = data.append(matched.groupdict(), ignore_index=True)
</code>```

Body:
I am parsing line by line through a massive text file (~10M lines) by regex to filter and clean up what need.

Each matched.groupdict() returns {'col1:'...','col2:'...','col3:'...'} which I would like to collect into a DataFrame. Just like a database, each entry would had its own index.

Over the past few days, I did tons of research on SO, Pandas.DataFrame docs, Coursera on DataFrames and nothing worked. Most solutions suggest creating a list of my groupdict() and then create a DataFrame, but that takes too much memory and I need it to be more dynamic.

What should I do?

pattern = re.compile("(?P<col1>...)(?P<col2>...)(?P<col3>...)")
data = pd.DataFrame()
with open("massive.txt", 'r') as massive:
    for line in massive:
        matched = pattern.search(line)
        if(matched):
            data.append(matched.groupdict(), ignore_index=True)

data
Empty DataFrame
Columns: []
Index: []

Body:
... silly me

...
data = data.append(matched.groupdict(), ignore_index=True)


问:
Memory leak problem NSAutoreleaseNoPool()
I am trying to create an immutable string. I am not initializing it with init, alloc or new but still the memory is leaking and its saying "object 0x234b533 of Class NSCFString autoreleased with no pool in place - just leaking " here is what I am trying to do

```<code>NSMutableString *srn = [NSMutableString stringwithCString:devSID];

// devSID is *char
</code>```

this leaves a leak. I have tried this too

```<code>NSMutableString *srn = [NSMutableString stringwithCString:devSID length:sizeof(devSID)];
</code>```

but this too doesn't work, however if I try initialize it with a simple string like this

```<code>NSMutableString *srn = @"this is my string";
</code>```

it works, dont have any idea whats happening around. I am not using init or alloc but still there is a leak. I would be obliged if anyone could help me out to resolve this issue

Regards

Umair

答:
Try something like this

[[NSString stringWithCString:"Hello"] retain];

retain is a way to assess object ownership on objects that you didn't initially create, so this extends our rule of matching every alloc with a release or autorelease

Note: You have to balance your release count if you retain this object. If you will not release retained object then you will face memory leak problem.

ContentLicense: CC BY-SA 2.5

Body:
I am trying to create an immutable string. I am not initializing it with init, alloc or new but still the memory is leaking and its saying "object 0x234b533 of Class NSCFString autoreleased with no pool in place - just leaking " here is what I am trying to do

NSMutableString *srn = [NSMutableString stringwithCString:devSID];

// devSID is *char

this leaves a leak. I have tried this too

NSMutableString *srn = [NSMutableString stringwithCString:devSID length:sizeof(devSID)];

but this too doesn't work, however if I try initialize it with a simple string like this

NSMutableString *srn = @"this is my string";

it works, dont have any idea whats happening around. I am not using init or alloc but still there is a leak. I would be obliged if anyone could help me out to resolve this issue

Regards

Umair


问:
Nginx metrics, SSL negotiation time metrics
I am trying find if there is any module or way to get metrics from NGINX and especially about SSL connection (Negotiation time etc.)

I ve searched also in access log but with no luck.

I ve also search to do that using somehow tcpdump to packet analysis

Is there anyway to do that from serve side to take those metrics?

答:
Not sure if this will answer your question but I hope that it can help...

Here are two web pages that I found that provide general information on Nginx metrics (including modules for metrics):

How to Monitor Nginx: The Essential Guide.

An In-Depth Guide to Nginx Metrics.

The first of these includes a section on "SSL Certificate expiration". But monitoring for SSL expiration dates and/or alerts for that seems limited in regards to the SSL connection metrics portion of your question.

On my searching for more SSL specific metric information for Nginx, I came across Module ngx_http_status_module. In the "SSL" subsection of the "Data" section of the page, I found mention of the following SSL statistics:

handshakes
  The total number of successful SSL handshakes.

handshakes_failed
  The total number of failed SSL handshakes.

session_reuses
  The total number of session reuses during SSL handshake.

I also found a paper Nginx SSL Performance that looked interesting to me in regards to Nginx SSL metrics albeit more from the perspective of a basis for what kinds of performance one can expect. It does however point out using openssl speed to gather metrics. Of course this presumes that Nginx was built with OpenSSL as the SSL library.

That leads me to the SSL library that your Nginx is built with. Whether it's OpenSSL or something else, it should have support for logging details. Here's a StackOverflow Q & A that's related to logging SSL details: nginx - log SSL handshake failures. While it doesn't sound like logs were the way you primarily wanted to get metrics from, it does seem like another resource even if you have to write some code to analyze them more conveniently.

Along the lines of analysis, I found the web page Debugging SSL Problems. While it's written with Apache's web server in mind, it does look like it would have helpful suggestions for analyzing and debugging Nginx SSL operations too.

As far as ways that perhaps you can get better answer(s), perhaps asking on the Server Fault Q & A site would help. You'll need to figure out how best to do that however as I recall seeing cross-posting being discouraged. Perhaps this Q & A can just be moved over to there since that seems like a more appropriate site for this. I don't know though.

Incidentally, I've written Nginx modules before and this question got more interesting to me as I dug into answering it.


问:
Substring between 2 indexes using recursion
I started learning Java, currently I'm playing around with recursion.

I wanted to try and make a substring method which will substring from both sides by 1 character until we get the desired string.

I managed to do the first part but I'm having problem figuring out how to substring from the back.

n and m should be the indexes between which we want to substring (inclusive).

In this example result of method should be "bstri"

Here is my code:

```<code>public static void main(String[] args) {
    String s = "substringme";

    System.out.println(rec(s,2,6));
}

public static String rec(String s, int n, int m) {
    if(n == 0 /* && missing 2nd part of condition */){
        return s;
    } else {
        if(n>0){
            s = s.substring(1);
            n--;
        }
        if(/* missing condition */){
            s= s.substring(0, s.length()-1);
        }
        return rec(s,n,m);
    }
}
</code>```

I would appreciate any help I can get.

答:
What you could do is look for the difference between m and the length of the string, and cut off characters from the end of the string until it is the correct length.

```<code>import java.util.*;
public class Test {
    public static void main(String[] args) {
        String s = "substringme";
        System.out.println(rec(s,2,6));
    }

    public static String rec(String s, int n, int m) {
        if(n == 0 && s.length()-m < 1){
            return s;
        } else {

            if(s.length()-m > 1){
                s= s.substring(0, s.length()-1);
            }
            else if(n>0){
                s = s.substring(1);
                n--;
            }
            return rec(s,n,m);
        }
    }
}
</code>```

Also shouldn't substring from 2 to 6 be "bstr", not "bstri"?

```<code>System.out.println(s.substring(2, 6)); //equals bstr
</code>```

Body:
I started learning Java, currently I'm playing around with recursion.

I wanted to try and make a substring method which will substring from both sides by 1 character until we get the desired string.

I managed to do the first part but I'm having problem figuring out how to substring from the back.

n and m should be the indexes between which we want to substring (inclusive).

In this example result of method should be "bstri"

Here is my code:

public static void main(String[] args) {
    String s = "substringme";

    System.out.println(rec(s,2,6));
}

public static String rec(String s, int n, int m) {
    if(n == 0 /* && missing 2nd part of condition */){
        return s;
    } else {
        if(n>0){
            s = s.substring(1);
            n--;
        }
        if(/* missing condition */){
            s= s.substring(0, s.length()-1);
        }
        return rec(s,n,m);
    }
}

I would appreciate any help I can get.

Body:
What you could do is look for the difference between m and the length of the string, and cut off characters from the end of the string until it is the correct length.

import java.util.*;
public class Test {
    public static void main(String[] args) {
        String s = "substringme";
        System.out.println(rec(s,2,6));
    }

    public static String rec(String s, int n, int m) {
        if(n == 0 && s.length()-m < 1){
            return s;
        } else {

            if(s.length()-m > 1){
                s= s.substring(0, s.length()-1);
            }
            else if(n>0){
                s = s.substring(1);
                n--;
            }
            return rec(s,n,m);
        }
    }
}

Also shouldn't substring from 2 to 6 be "bstr", not "bstri"?

System.out.println(s.substring(2, 6)); //equals bstr


问:
How to read properties of a executable file?
I want to read the file properties like File Description , Product name , Copyright of a exe file. Is there any Windows API for it?

答:
Yes. It may not be evident to find it because the Version Information chapter is hidden below Menus and other Resources. The rationale for that is that it is stored is the executable files (including DLL) as a VERSIONINFO resource that was originally intented to help install tools to know whether the version to install was more recent than an existing version.

You will find examples for using it in the linked page to the MSDN and also in SO in different places, for example here


问:
dataentry form , how to define subform in main form
I want to create a form for dataentry in access.  I Have these tables.
enter image description here

I have a personaldetail table, which includes information about student first name, last name, etc.
I have information about technical skills which has different groups (6 groups) programming, languages,banking, etc.

Each group has different parts: for example, Programming has 4 parts JAVA, PHP, C, Python.
Languages also have different parts English, German, Spanish, French

Banking has these parts: Risk Management, Project Management

Each student has different skills; first student knows Java, php, German, Project ManagementI have these tables.

I have main form for personal details how should I define subform which allows to enter data about skills.

答: Not really clear what the issue is. Main form bound to PersonalDetails and Subform bound to [student skill] with a combobox to select skill. Basic Access functionality. Perhaps you need cascading (dependent) comboboxes. Select group in combobox 1 and this causes combobox 2 list to filter to only those skills associated with that group. Common requirement, however, doesn't work nicely in a continuous or datasheet form if the combobox list displays lookup alias. </p>


问:
laravel how to reduce queries for count, eager load?
Say I have 3 models

Users

Attendees

ScheduleProgramSegments

Attendees belongs to Users

User hasMany Attendees

Bookings is a pivot relation

Attendees belongsToMany ScheduledProgramSegments  (pivot table = bookings)

I am getting the count of the pivot relation and I have about 600 too many queries because it keeps querying the count for each scheduled_program_segment_id...I do not know how to get them all in one query...eager load or otherwise.

Queries being run (shown by debugbar)

```<code>select * from `scheduled_program_segments` where `scheduled_program_segments`.`scheduled_program_id` = '477'410μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1392' and `bookings`.`registered` = '1'450μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1392' and `bookings`.`registered` = '1'390μs
select * from `scheduled_program_segments` where `scheduled_program_segments`.`scheduled_program_id` = '478'420μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1393' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1393' and `bookings`.`registered` = '1'390μs
select * from `program_sessions` where `program_sessions`.`id` = '23' limit 1390μs
select * from `scheduled_program_segments` where `scheduled_program_segments`.`scheduled_program_id` = '478'450μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1393' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1393' and `bookings`.`registered` = '1'380μs
select * from `scheduled_program_segments` where `scheduled_program_segments`.`scheduled_program_id` = '481'730μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1396' and `bookings`.`registered` = '1'400μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1396' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1397' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1398' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1399' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1400' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1401' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1402' and `bookings`.`registered` = '1'440μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1403' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1404' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1405' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1406' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1407' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1408' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1409' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1410' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1411' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1412' and `bookings`.`registered` = '1'430μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1413' and `bookings`.`registered` = '1'
</code>```

EDIT

Eager loading in controller

```<code>$programs = ScheduledProgram::with('scheduledProgramSegments.registeredAttendees','scheduledProgramSegments.attendees')->where('registration_start_date', '<=', $today)
                            ->where('end_date',                '>=',  $today)
                            ->get();

$user->load('attendees', 'attendees.scheduledProgramSegments')->get();

return View::make('user/registration/edit', compact('user','programs'));
</code>```

ScheduledProgram Model

```<code>     public function scheduledProgramSegments()
  {
    return $this->hasMany('ScheduledProgramSegment');
  }
  public function program()
  {
    return $this->belongsTo('Program');
  }
  public function programSession()
  {
    return $this->belongsTo('ProgramSession');
  }
  public function attendees()
  {
    return $this->belongsToMany('Attendee', 'prog_bookings')->withPivot('registered','paid')->withTimestamps();
    //return $this->hasManyThrough('Attendee', 'ScheduledProgramSegment','id','id' );
  }

  public function registeredAttendees()
  {
      //return $this->scheduledProgramSegments->attendees()->wherePivot('registered', 1);
      return $this->attendees()->wherePivot('registered', 1);
  }
  public function getRegisteredCountAttribute()
  {
    //return $this->registeredAttendees->count();
    //Consider changing this to calculate the max registered of the child programs
    $largest = 0;
    $segments = $this->scheduledProgramSegments()->get();
//return $segments->first()->registered_count;
    foreach($segments as $segment){
      $largest = ($segment->registered_count > $largest) ? $segment->registered_count : $largest;
    }
    return $largest;
  }
</code>```

Attendee Model

```<code>public function user()
{
    return $this->belongsTo('User');
}

public function scheduledProgramSegments()
{
    return $this->belongsToMany('ScheduledProgramSegment', 'bookings')->withPivot('paid','registered')->withTimestamps();
}
</code>```

View

```<code>  <td class="cap">{{{$program->registered_count . '/' . $program->max_attendees}}}</td>
</code>```

答:
Change getRegisteredCountAttribute function to

```<code> public function getRegisteredCountAttribute()
 {
      //return $this->registeredAttendees->count();
      //Consider changing this to calculate the max registered of the child programs
      $largest = 0;
      $segments = $this->with('scheduledProgramSegments')->get(); // this is the line to change. this will prevent the N+1 query problem.

      //return $segments->first()->registered_count;
      foreach($segments as $segment){
           $largest = ($segment->registered_count > $largest) ? $segment->registered_count : $largest;
      }

      return $largest;
</code>```

}

and this too

```<code> public function registeredAttendees()
 {
    //return $this->scheduledProgramSegments->attendees()->wherePivot('registered', 1);
    return $this->with('attendees')->wherePivot('registered', 1);
 }
</code>```

Body:
Say I have 3 models

Users

Attendees

ScheduleProgramSegments

Attendees belongs to Users

User hasMany Attendees

Bookings is a pivot relation

Attendees belongsToMany ScheduledProgramSegments  (pivot table = bookings)

I am getting the count of the pivot relation and I have about 600 too many queries because it keeps querying the count for each scheduled_program_segment_id...I do not know how to get them all in one query...eager load or otherwise.

Queries being run (shown by debugbar)

select * from `scheduled_program_segments` where `scheduled_program_segments`.`scheduled_program_id` = '477'410μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1392' and `bookings`.`registered` = '1'450μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1392' and `bookings`.`registered` = '1'390μs
select * from `scheduled_program_segments` where `scheduled_program_segments`.`scheduled_program_id` = '478'420μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1393' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1393' and `bookings`.`registered` = '1'390μs
select * from `program_sessions` where `program_sessions`.`id` = '23' limit 1390μs
select * from `scheduled_program_segments` where `scheduled_program_segments`.`scheduled_program_id` = '478'450μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1393' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1393' and `bookings`.`registered` = '1'380μs
select * from `scheduled_program_segments` where `scheduled_program_segments`.`scheduled_program_id` = '481'730μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1396' and `bookings`.`registered` = '1'400μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1396' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1397' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1398' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1399' and `bookings`.`registered` = '1'390μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1400' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1401' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1402' and `bookings`.`registered` = '1'440μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1403' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1404' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1405' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1406' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1407' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1408' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1409' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1410' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1411' and `bookings`.`registered` = '1'380μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1412' and `bookings`.`registered` = '1'430μs
select count(*) as aggregate from `attendees` inner join `bookings` on `attendees`.`id` = `bookings`.`attendee_id` where `bookings`.`scheduled_program_segment_id` = '1413' and `bookings`.`registered` = '1'

EDIT

Eager loading in controller

$programs = ScheduledProgram::with('scheduledProgramSegments.registeredAttendees','scheduledProgramSegments.attendees')->where('registration_start_date', '<=', $today)
                            ->where('end_date',                '>=',  $today)
                            ->get();

$user->load('attendees', 'attendees.scheduledProgramSegments')->get();

return View::make('user/registration/edit', compact('user','programs'));

ScheduledProgram Model

     public function scheduledProgramSegments()
  {
    return $this->hasMany('ScheduledProgramSegment');
  }
  public function program()
  {
    return $this->belongsTo('Program');
  }
  public function programSession()
  {
    return $this->belongsTo('ProgramSession');
  }
  public function attendees()
  {
    return $this->belongsToMany('Attendee', 'prog_bookings')->withPivot('registered','paid')->withTimestamps();
    //return $this->hasManyThrough('Attendee', 'ScheduledProgramSegment','id','id' );
  }

  public function registeredAttendees()
  {
      //return $this->scheduledProgramSegments->attendees()->wherePivot('registered', 1);
      return $this->attendees()->wherePivot('registered', 1);
  }
  public function getRegisteredCountAttribute()
  {
    //return $this->registeredAttendees->count();
    //Consider changing this to calculate the max registered of the child programs
    $largest = 0;
    $segments = $this->scheduledProgramSegments()->get();
//return $segments->first()->registered_count;
    foreach($segments as $segment){
      $largest = ($segment->registered_count > $largest) ? $segment->registered_count : $largest;
    }
    return $largest;
  }

Attendee Model

public function user()
{
    return $this->belongsTo('User');
}

public function scheduledProgramSegments()
{
    return $this->belongsToMany('ScheduledProgramSegment', 'bookings')->withPivot('paid','registered')->withTimestamps();
}

View

  {{{$program->registered_count . '/' . $program->max_attendees}}}

Body:
Change getRegisteredCountAttribute function to

 public function getRegisteredCountAttribute()
 {
      //return $this->registeredAttendees->count();
      //Consider changing this to calculate the max registered of the child programs
      $largest = 0;
      $segments = $this->with('scheduledProgramSegments')->get(); // this is the line to change. this will prevent the N+1 query problem.

      //return $segments->first()->registered_count;
      foreach($segments as $segment){
           $largest = ($segment->registered_count > $largest) ? $segment->registered_count : $largest;
      }

      return $largest;

}

and this too

 public function registeredAttendees()
 {
    //return $this->scheduledProgramSegments->attendees()->wherePivot('registered', 1);
    return $this->with('attendees')->wherePivot('registered', 1);
 }


问:
Multiple Eddystone-URL/UID's from same Bluetooth Beacon?
Is it possible to program a BT beacon to advertise a sequence of different Eddystone-URL/UID's in sequence?  I imagine I could from something like a Raspberry Pi3 with a BT adapter, but I was wondering about something like an actual beacon.  </p>

答: I dont think so. Im pretty sure you would need to have some smart device nearby that is running a program that is periodically changing the UIDs. The micro-controllers that power these beacons are pretty bare bones and are really optimized for transmitting bluetooth signals.</p>


问:
Problem with max SQL function
I have this code in PHP

```<code>$max="SELECT MAX(num) FROM info";
$maxquery= mysql_query($max) or die (died);
while($row = mysql_fetch_array($maxquery)){
    echo "The max num is ". $row['num']."this is it";
}
$maxnum= mysql_fetch_array($maxquery);
echo "<br>".$maxnum."hh";
</code>```

then the output be:

The max num is this is it

hh

Why didn't the query get the max number?

The table is called info and it has these fields, ID, num, title, description, and answer.

After editing:

I tried my query in MySQL and it works fine!

"SELECT MAX(num) FROM info"

and this is my complete code if it can help:

```<code><?php
    $answer=$_GET["answerbox"];
    $ID=$_GET["TheID"];

    $host="localhost";
    $username="root";
    $password="";
    $db_name="game";
    mysql_connect("$host","$username","$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $max="SELECT MAX(num) FROM info";
    $maxquery= mysql_query($max) or die (died);
    while($row = mysql_fetch_array($maxquery)) {
        echo "The max num is ". $row['num']."this is it";
    }

    $maxnum= mysql_fetch_array($maxquery);
    $sql="SELECT * FROM info  WHERE ID=".$ID;
    $query = mysql_query($sql) or die(errorquery);
    $row = mysql_fetch_array($query);
    $trueanswer = $row['Answer'];
    $num=$row['num'];
    if ($num<$maxnum)
    {
        $numto= $num +1 ;
        echo "<br>".$maxnum."hh";
    }
?>
</code>```

答:
It's because your query returns a scalar value, not an array. $maxquery is the value you want to get.

I recommend checking your query against the database before try running it with PHP.

Title: Problem with max SQL function

Body:
I have this code in PHP

$max="SELECT MAX(num) FROM info";
$maxquery= mysql_query($max) or die (died);
while($row = mysql_fetch_array($maxquery)){
    echo "The max num is ". $row['num']."this is it";
}
$maxnum= mysql_fetch_array($maxquery);
echo "
".$maxnum."hh";

then the output be:

The max num is this is it

hh

Why didn't the query get the max number?

The table is called info and it has these fields, ID, num, title, description, and answer.

After editing:

I tried my query in MySQL and it works fine!

"SELECT MAX(num) FROM info"

and this is my complete code if it can help:

<?php
    $answer=$_GET["answerbox"];
    $ID=$_GET["TheID"];

    $host="localhost";
    $username="root";
    $password="";
    $db_name="game";
    mysql_connect("$host","$username","$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $max="SELECT MAX(num) FROM info";
    $maxquery= mysql_query($max) or die (died);
    while($row = mysql_fetch_array($maxquery)) {
        echo "The max num is ". $row['num']."this is it";
    }

    $maxnum= mysql_fetch_array($maxquery);
    $sql="SELECT * FROM info  WHERE ID=".$ID;
    $query = mysql_query($sql) or die(errorquery);
    $row = mysql_fetch_array($query);
    $trueanswer = $row['Answer'];
    $num=$row['num'];
    if ($num<$maxnum)
    {
        $numto= $num +1 ;
        echo "
".$maxnum."hh";
    }
?>


问:
I already have my web application script at place using selenium webDriver ,how can i integrate that with jmeter
I have my web Application automation script using Selenium WebDriver,i want to use it with jmeter for Performance testing of my application

*I have tried using Webdriver sampler(as i cannot use my code with this ) and Junit Request sampler

Kindly Suggest some better way to integrate and monitor it

答:
I don't think you will be able to reuse your Selenium tests for conducting the load test as browsers (even headless like HtmlUnit or PhantomJS) are very CPU intensive and have huge memory footprint so most likely you won't be able to kick off the required number of browsers.

I would recommend converting your Selenium tests into "pure" JMeter HTTP-protocol based load tests, this way you will be able to simulate hundreds of virtual users form mid-level laptop.

Start JMeter's HTTP(S) Test Script Recorder

Configure your Selenium test to use JMeter as a proxy

Run your test

Perform correlation and parameterization if required

You should be ready to use JMeter test for load testing

You may also be interested in How to Convert Selenium Scripts into the JMX article which describes an alternative way of conversion.


问:
OPC UA java library
I am new to OPC UA standard and being a java developer was trying to search for a good java library for the standard.

I cam across https://github.com/OPCFoundation/UA-Java and Eclipse Milo(or digitalpetri).

How does Eclipse Milo compare with UA-Java? which one should I choose?

My use case is to develop a NIFI(nifi.apache.org) custom processor that can read data from an OPC UA server like Kepware and channel that data into our bigdata store and later build analytics on top of it.  I want to implement OPC features like subscription and historical data access as well in the processor.

答:
You might find these links on the subject helpful to your effort
  https://community.hortonworks.com/articles/90355/collect-data-from-opc-ua-protocol.html

https://community.hortonworks.com/articles/88649/control-system-data-from-kepware.html

Title: OPC UA java library


问:
Running functions from a child directory
So I have a deployment process that copies my web jobs to a folder structure like \app_data\jobs\triggered|continuous\jobname. I'm currently looking into keeping the existing folder structure for people who are self hosting and running jobs out of process not on azure, as well as wanting to be able to run azure functions. I was hoping just to put a function.json in the existing folder structure and have the functions picked up but I have multiple problems with this.

I have a run.bat which needs to copy dependencies from bin folder to jobs folder on run. I see docs on how to do this in java but nothing more on how configuration runs. Basically, I'd want to do a copy and then call my specific compiled function with parameters defined and not some Main() static method

I don't see how you'd tell the host.json file to look into a sub folder or even sub folders recursively.. There seems to be no docs on this other than possibly creating a new Job Host and specify it in code (which I do not what to do). I don't want any dependencies on azure libs.

So my next idea was that I could also just copy the jobs exe to the bin folder and then the problem with run.bat goes away (#1 above) and place all the functions in (\app_data\functions\jobname). But then I wonder how would I specify this sub folder that contains my functions..

Please help.

Source for my project can be found here if your curious (https://github.com/exceptionless/Exceptionless/tree/feature/azure-functions). I'm working on getting the following job working first (https://github.com/exceptionless/Exceptionless/blob/feature/azure-functions/src/Jobs/EventPost/Program.cs) Here is how my artifacts are created as part of the git deploy process (https://github.com/exceptionless/Exceptionless/blob/feature/azure-functions/build/Push-Artifacts.ps1#L41)

答:
One thing that might help you is the ITypeLocator, which gives you control over the types that are indexed. You can set your own ITypeLocator in JobHostConfiguration.

Another is WebHostSettings, which lets you set ScriptsPath - where functions are discovered. This is not configurable at present while running in azure, I suggest you file an issue and put in a PR to change that.


问:
ERROR_MESSAGE_MAIN ERROR_MESSAGE_REASON on iPad and iPhone Safari
My website has a functionality of downloading excel sheet. I'm using PHPExcel library with Codeigniter to create the .xlsx sheet. It works fine almost everywhere but in iPad/ iPhone Safari. The following error covers the screen.
 Safari Error Screenshot

My code to download the file is following:

ob_end_clean();

$filename='attendance_list.xlsx';

header('Content-Type: application/vnd.ms-excel');

header('Content-Disposition: attachment;filename="'.$filename.'"');

header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');

$objWriter->save('php://output');

And i am calling the php function with this code via jquery and AJAX. Please provide me with the answers.

答:
instead of:

header('Content-Type: application/vnd.ms-excel');

use

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');


问:
JavaScript non selectable text not working in Chrome/Internet Explorer
In Firefox seems fine, Chrome and Internet Explorer the text is still selectable, is there any way around this? The code was taken from another question, (which I can't find right now) so it may be out of date?

```<code>// Prevent selection
function disableSelection(target) {
    if (typeof target.onselectstart != "undefined") // Internet Explorer route
        target.onselectstart = function() { return false }
    else if (typeof target.style.MozUserSelect != "undefined") // Firefox route
        target.style.MozUserSelect = "none"
    else // All other routes (for example, Opera)
        target.onmousedown = function() { return false }
}
</code>```

Used in code as:

```<code>disableSelection(document.getElementById("gBar"));
</code>```

答:
For Wekbit (e.g. Chrome and Safari) you can add:

```<code>else if (typeof target.style.webkitUserSelect != "undefined") // Webkit route
    target.style.webkitUserSelect = "none";
</code>```

For IE, use 'unselectable':

```<code>else if (typeof target.unselectable != "undefined") // IE route
    target.unselectable = true;
</code>```

Reference: http://help.dottoro.com/ljrlukea.php

ContentLicense: CC BY-SA 4.0

Body:
In Firefox seems fine, Chrome and Internet Explorer the text is still selectable, is there any way around this? The code was taken from another question, (which I can't find right now) so it may be out of date?

// Prevent selection
function disableSelection(target) {
    if (typeof target.onselectstart != "undefined") // Internet Explorer route
        target.onselectstart = function() { return false }
    else if (typeof target.style.MozUserSelect != "undefined") // Firefox route
        target.style.MozUserSelect = "none"
    else // All other routes (for example, Opera)
        target.onmousedown = function() { return false }
}

Used in code as:

disableSelection(document.getElementById("gBar"));

Body:
For Wekbit (e.g. Chrome and Safari) you can add:

else if (typeof target.style.webkitUserSelect != "undefined") // Webkit route
    target.style.webkitUserSelect = "none";

For IE, use 'unselectable':

else if (typeof target.unselectable != "undefined") // IE route
    target.unselectable = true;

Reference: http://help.dottoro.com/ljrlukea.php


答:
With dplyr...

```<code>mtcars %>% group_by(cyl) %>% mutate(pairmean=(mpg+lag(mpg))/2)
</code>```

Title: Calculate mean of serial pairs of values by group

Body:
With dplyr...

mtcars %>% group_by(cyl) %>% mutate(pairmean=(mpg+lag(mpg))/2)


问:
View function did not return a response in flask
I have a code below which setups cookie and then adds this cookie to the response with set_cookies function. However, even though I return a response I received the following error:

ValueError: View function did not return a response

My code is simply this:

```<code>def login():

 if request.method == "POST":
    timestamp = str(int(time.time()))
    cookie = timestamp+'user'
    cookie = base64.b64encode(cookie.encode('utf-8')).decode('utf-8')
    resp = make_response()
    resp = resp.set_cookie("LoginCookie",cookie)
    return resp
</code>```

答:
response.set_cookie is an in-place operation. This means that if you set something to it's return value, it will be None, which is the default return value (functions with no return return None).
What should be used instead is:</p>

```<code>resp.set_cookie("LoginCookie",cookie)
</code>```

Body:
I have a code below which setups cookie and then adds this cookie to the response with set_cookies function. However, even though I return a response I received the following error:

ValueError: View function did not return a response

My code is simply this:

def login():

 if request.method == "POST":
    timestamp = str(int(time.time()))
    cookie = timestamp+'user'
    cookie = base64.b64encode(cookie.encode('utf-8')).decode('utf-8')
    resp = make_response()
    resp = resp.set_cookie("LoginCookie",cookie)
    return resp

Body:
response.set_cookie is an in-place operation. This means that if you set something to it's return value, it will be None, which is the default return value (functions with no return return None).
What should be used instead is:

resp.set_cookie("LoginCookie",cookie)


问:
imhist matlab does not work
I am using MATLAB for image processing and when I run a simple example:

```<code>I=imread('img.png');
imhist(I)
</code>```

it shows me this error:
    Error using imhist

```<code>Expected input number 1, I or X, to be two-dimensional.

Error in imhist>parse_inputs (line 278)
validateattributes(a,  {'double','uint8','int8','logical','uint16','int16','single','uint32',
'int32'}, ...

Error in imhist (line 60)
[a, n, isScaled, top, map] = parse_inputs(varargin{:});
</code>```

I am using an RGB image.

答:
imhist() would work only for gray scale images.

So first convert your RGB image to gray scale:

```<code>I=imread('img.png');
gray = rgb2gray(I);   #---Convert your image to gray scale

[Hist_Gray, x] = imhist(gray);    #---Obtain the histogram

plot(x, Hist_Gray, 'Gray');    #---Plot the histogram
</code>```

Title: imhist matlab does not work

Body:
I am using MATLAB for image processing and when I run a simple example:

I=imread('img.png');
imhist(I)

it shows me this error:
    Error using imhist

Expected input number 1, I or X, to be two-dimensional.

Error in imhist>parse_inputs (line 278)
validateattributes(a,  {'double','uint8','int8','logical','uint16','int16','single','uint32',
'int32'}, ...

Error in imhist (line 60)
[a, n, isScaled, top, map] = parse_inputs(varargin{:});

I am using an RGB image.

Body:
imhist() would work only for gray scale images.

So first convert your RGB image to gray scale:

I=imread('img.png');
gray = rgb2gray(I);   #---Convert your image to gray scale

[Hist_Gray, x] = imhist(gray);    #---Obtain the histogram

plot(x, Hist_Gray, 'Gray');    #---Plot the histogram


问:
How can I draw a arrow for showing incoming/ outgoing calls
I'm creating an app that shows Call Log.

In most of the contacts app we see arrows representing incoming/outgoing/missed calls.

where can I get them or can I create them using drawables or something?

答:
You can install and use this plugin - Android Material Design Icon Generator - in Android Studio. It has a collection of several icons. It will also automatically put different sizes of drawables in their respective drawable folders.

To install a plugin in Android Studio: Goto settings/preferences -> plugins -> browse repositories.